I am trying to understand what is the difference between the commands docker stop ContainerID
and docker pause ContainerID
. According to this page both of them are used to pause an existing Docker container.
docker stop
and docker pause
?docker stop
: Send SIGTERM
(termination signal), and if needed SIGKILL
(kill signal)docker pause
: Send SIGSTOP
(pause signal)
SIGTERM
: The default behavior is to terminate the process, but it also can be caught or ignored. The intention is to kill the process, gracefully or not, but first give it a chance to clean up.
SIGKILL
: The only behavior is to kill the process, immediately. As the process cannot catch the signal, it cannot clean up; thus, this is a signal of last resort.
SIGSTOP
: The only behavior is to pause the process; the signal cannot be caught or ignored. The shell uses pausing (and its counterpart, resuming via SIGCONT) to implement job control
docker stop
and docker pause
?docker stop
: When you wish to clear up memory or delete all of the processes' -cached- data. Simply put, you no longer care about the processes in the container and are comfortable with killing them.docker pause
: When you only want to suspend the processes in the container; you do not want them to lose data or state.Example:
Consider a container with a counter. Assume the counter has reached 3000. Running docker stop
will cause the counter to lose its value and you will be unable to retrieve it. Using docker pause
, on the other hand, will maintain the counter state and value.
Hope it's clear now!