Stop docker container from alpine image

I'm trying to stop a docker container from an alpine image:

> docker run -ti alpine sh
/ # poweroff
/ # poweroff -f
poweroff: Operation not permitted
/ # halt
/ # halt -f
halt: Operation not permitted
/ # whoami
root

      

Do you see what is the problem with this?

+3


source to share


2 answers


You cannot stop the docker image this way.

Firstly, if it poweroff

had to function (and it was in the past, due to a problem ), it would stop the entire computer, because of how the binary works poweroff

, and the power-stop mechanic is designed on Linux and hardware.

What needs to be done to properly stop your container is to exit the entry point ( exit

in the shell) or send a signal to this process (for example: docker stop

send SIGTERM

to the current entry point before killing it after the grace period).

If you really want to unplug the host from the container (why would you ever want to do that?), You can enable the option --privileged

to give all the power to your root in the container, then do:



echo 1 > /proc/sys/kernel/sysrq; echo o > /proc/sysrq-trigger

Be careful, this will really stop the master and is brutal. Writing 1

to sysrq

activates kernel functions sysrq

, which allows keyboard requests to the kernel using the SysRq key , but also through a file sysrq-trigger

. o

means poweroff.

Fedora Project - Sysrq

+3


source


You need to end the process sh

simply by using this:

exit

      



From the container. Think of a container as an isolated process rather than a virtual machine.

+3


source







All Articles