I'm trying out Docker and came across
docker container stop <hash> # Gracefully stop the specified container
I'm not asking about the difference between docker stop and docker kill. I'm wondering about the term "gracefully"
What does "gracefully stop" mean in this context?
A graceful shutdown is when a computer is turned off by software function and the operating system (OS) is allowed to perform its tasks of safely shutting down processes and closing connections. A hard shutdown is when the computer is forcibly shut down by interruption of power.
To terminate a container, Docker provides the docker stop and docker kill commands. Both the docker kill and docker stop commands look similar, but their internal execution is different. The docker stop commands issue the SIGTERM signal, whereas the docker kill commands sends the SIGKILL signal.
Note that pressing `Ctrl+C` when the terminal is attached to a container output causes the container to shut down.
For a major version upgrade, one has to tear down all running containers. With a restart policy of always , however, the containers will be restarted after the docker daemon is restarted after the upgrade.
Your question is related to the difference between SIGTERM
and SIGKILL
.
SIGTERM: When a process receives this signal, it has the chance to perform cleanup. That's the so-called "graceful" exit; it corresponds to docker stop
.
SIGKILL: The process doesn't even know it has received this signal and it has no chance to ignore or do anything about it. The process directly exits. That's the so-called "not graceful" exit; it corresponds to docker kill
.
For further details look at this topic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With