Stopping and starting containers
Sometimes, we want to (temporarily) stop a running container. Let’s try this out with the trivia container we used previously:
- Run the container again with this command:
$ docker container run -d --name trivia fundamentalsofdocker/trivia:ed2
- Now, if we want to stop this container, then we can do so by issuing this command:
$ docker container stop trivia
When you try to stop the trivia container, you will probably notice that it takes a while until this command is executed. To be precise, it takes about 10 seconds. Why is this the case?
Docker sends a Linux SIGTERM
signal to the main process running inside the container. If the process doesn’t react to this signal and terminate itself, Docker waits for 10 seconds and then sends SIGKILL
, which will kill the process forcefully and terminate the container.
In the preceding command, we have used the name of the container to specify which container we want to stop. But we...