Restarting the host from the docker container

As indicated in the header, is it possible to restart the host from the container? I have a docker container working with systemd as described here and started as:

$ docker run -privileged --net host -ti -d -v /sys/fs/cgroup:/sys/fs/cgroup:ro <image_name> 

As soon as I systemctl reboot command, I see:

 # systemctl reboot [ root@dhcp-40-115 /]# [3]+ Stopped 

The host does not restart. However, I see [1915595.016950] systemd-journald[17]: Received SIGTERM from PID 1 (systemd-shutdow). in the host kernel buffer.

Use Case:

I am experimenting with launching

+7
docker
source share
3 answers

I was able to send sysrq commands to the host installation /proc/sysrq-trigger as a volume.

This loaded the host.

 docker-server# docker run -i -t -v /proc/sysrq-trigger:/sysrq centos bash docker-container# echo b > /sysrq 

You can set the permission for the bitmask to /proc/sys/kernel/sysrq on the host to allow, for example, to synchronize disks and boot. More information about this can be found at http://en.wikipedia.org/wiki/Magic_SysRq_key , but something like this (untested) should set these permissions:

 echo 144 > /proc/sys/kernel/sysrq 

Also, do not forget to add kernel.sysrq = 144 to /etc/sysctl.conf to save it upon reboot.

+4
source share

There is one detail that I missed in my question above, which I once ran systemd in the container itself, systemctl reboot (roughly speaking), connecting to systemd in the container itself, which is not what I want.

At the prompt of a colleague, here's what I did on the Fedora stock image (nothing special about it):

 $ docker run -ti -v /run/systemd:/run/systemd fedora /bin/bash 

Then in the container:

 bash-4.2# systemctl status docker docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled) Active: active (running) since Tue 2014-07-01 04:57:22 UTC; 2 weeks 0 days ago Docs: http://docs.docker.io Main PID: 2589 CGroup: /system.slice/docker.service 

Here the container has access to systemd on the host. Then issuing the reboot command actually reboots the host:

 bash-4.2# reboot 

Thus, you can restart the host from the container.

It should be noted that the host runs Fedora 20, as well as in the container. If the host was another distribution not run by systemd , this would not be possible. Generally speaking, if the host and container start distributions that do not start systemd or incompatible versions of systemd, this will not work.

+5
source share

Adding a response to user59634:

-v /run/systemd:/run/systemd runs on Fedora 27 and ubuntu 16

But you only need one socket

docker run -it --rm -v /run/systemd/private:/run/systemd/private fedora reboot

You can also use /run/dbus , but I like this systemd method more. I do not quite understand how much energy you give the container, I suspect that this is enough to capture your master. Therefore, I would suggest using this in the container that you wrote, and then exchange information with any other container, see here .

Unrelated similar information

Hibernate / suspend / hibernate can only be done with -v /sys/power/state:/sys/power/state and with /lib/systemd/systemd-sleep suspend , for example. If you know how to do this, you can echo the line directly to /sys/power/state , for example echo mem > /sys/power/state here for a more detailed explanation of the various parameters you get from cat /sys/power/state

0
source share

All Articles