I would like to shutdown the machine (host) when the docker container finishes a job.
My host OS is Ubuntu.
The container can run as --privileged=true
. That is not a problem.
I managed to do this with the command (found in a stackoverflow answer):
subprocess.run("echo 1 > /proc/sys/kernel/sysrq; echo o > /proc/sysrq-trigger", shell=True, check=True)
The problem with this approach it is immediate, unclean shutdown in Linux.
If I try a clean way as a shutdown now
, I get the following error: System has not been booted with systemd as init system (PID 1). Can't operate.
How can I use shutdown or halt or other alternative within my container to shutdown the host?