Reputation: 6062
When the docker container has, for example, 100 processes running and we restart the container using docker restart container-name
how can docker restart all these 100 processes?
Will it store all the processes details and start them again?
Edit:
The following can be considered as specific question that I want to be answered:
After starting a container, I login to the container using docker exec -it container-name bash
and I start some background processes. Then I exit the container and do a docker restart
or a stop
followed by a start
. Will I get those manually started processes running again automatically?
Upvotes: 8
Views: 14008
Reputation: 159875
A Docker container has one primary process. docker restart
does two things:
docker stop
. It sends SIGTERM to its primary process (only); if that doesn't terminate within 10 seconds, it sends SIGKILL. If the primary process still has children, they also get forcibly terminated.docker start
. In the container that already exists, it runs the container's command, constructed by concatenating its entrypoint and command lists.Note that both of these focus on one process. If that process is a dedicated process manager like supervisord, the docker stop
sequence will hopefully cause the supervisor to gracefully stop every process it's managing and you'll be okay. If it's a shell script that starts a bunch of background processes and ignores them, they'll just get killed with no warning. Similarly, if the main container process knows how to start its children then docker start
will cause that to happen again, but if it was an interactive shell and you hand-started background processes, they are lost.
Docker doesn't have any sort of "snapshot" mechanism. The general model is that containers always start from a clean and known state, and can reconstruct whatever they need from there. It fits better with this model to docker rm
a stopped container and docker run
a new one than to try to docker start
it again.
Upvotes: 14
Reputation: 1143
First of all, having 100 processes running in a container doesn't sound great, as per the guidelines in the Dockerfile best practices. Just something to keep in mind; if it works for you, then that's fine.
If those 100 processes come to be as part of the container startup process, then you'll have them running again after the restart. That is completely up to what your container is supposed to do, and how, i.e. what's your ENTRYPOINT
doing.
restart
is a stop
, and then a start
. So I guess a very loose parallel would be with your computer. After you restart it, it will run those startup programs that you have, e.g. network management, whatever. But it won't restart your browser, unless you explicitly hook up your OS to do so.
If, as part of container's run, files are written on the disk, then after a restart you'll have them there. This is also something that you should probably not leverage, unless it really suits your use-case. This is because containers are meant to be ephemeral.
Upvotes: 3