I have a host machine which has one docker container. The container is active and running a particular service. On meeting a particular condition, I want to remove the container and shut down the machine also. Is it possible to do so? I am planning to modify the code which runs the service to handle the shutting down of the machine? Any suggestions are welcome!
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- What would prevent code running in a Docker contai
- How to reload apache in php-apache docker containe
Running a clean shutdown will be dependent on the hosts init system.
To avoid giving the container
--privileged
access and to also avoid installing host specific init tools in your container, you could create an interface to signal the host to shutdown rather than the trying to get the container to run the shutdown.An Interface
There's many ways this could be done. A simple starting point could be a mounted volume to share data between the container and host. A file will do for now but you could use a socket, fifo, TCP or any other IPC method you want.
Create a file on the host, say
/var/run/shutdown_signal
and mount the file into your containerWrite a string into the file when you want the host to shutdown
Then you need something running on the host to monitor the file.
A simple script that waits for file changes with
inotifywait
.You could poll the file if
inotifywait
is not available.The Horrible Alternative
There is also a more universal, kernel way to trigger an immediate, unclean shutdown in Linux.
But this will likely cause more issues for you than it's worth.
Have you tried this?