pause vs stop in docker
Asked Answered
G

5

53

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.

Graphic answered 22/7, 2018 at 14:34 Comment(1)
Please see also the official docs.Kathiekathleen
S
63

The docker pause command suspends all processes in the specified containers. On Linux, this uses the cgroups freezer. Traditionally, when suspending a process the SIGSTOP signal is used, which is observable by the process being suspended

https://docs.docker.com/engine/reference/commandline/pause/

The docker stop command. The main process inside the container will receive SIGTERM, and after a grace period, SIGKILL.

https://docs.docker.com/engine/reference/commandline/stop/#options

SIGTERM is the termination signal. 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 to first allow it a chance to cleanup.

SIGKILL is the kill signal. The only behavior is to kill the process, immediately. As the process cannot catch the signal, it cannot cleanup, and thus this is a signal of last resort.

SIGSTOP is the pause signal. 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.

Sarina answered 22/7, 2018 at 15:46 Comment(2)
after docker pause, if I restart my laptop, will I manage to continue the process? may be not, right?Sidhu
If you restart the process, any processes frozen by SIGSTOP will be destroyed, and you cannot SIGCONT them. A reboot kills the main root process from which all other processes descend and restarts it. If you suspend (or "sleep") your computer, the process tree is preserved and can be resumed.Helbon
T
23

What is the difference between 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

When to use 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!

Thedathedric answered 15/6, 2022 at 23:47 Comment(1)
This is the answer which cleared by doubt. You explained with a real world scenario, thank youSalinas
D
13

And addition to the answers added earlier

running docker events after docker stop shows events

  • kill (signal 15): where signal 15 = SIGTERM
  • die
  • stop

running docker events after docker pause shows only one event

  • pause

Also docker pause would still keep memory portion while the container is paused. This memory is used when the container is resumed. docker stop releases the memory used after the container is stopped.

This table has even more details.

Delinquency answered 3/11, 2018 at 7:47 Comment(0)
A
4

docker pause pauses (i.e., sends SIGSTOP) pauses (read: suspends) all the processes in a container[s].

docker stop stops (i.e., sends SIGTERM, and if needed SIGKILL) to the conrainer[s]'s main process.

Arsonist answered 22/7, 2018 at 15:22 Comment(2)
after docker pause, if I restart my laptop, will I manage to continue the process? may be not, right?Sidhu
@Sidhu Why don't you try it out and report your results?Sigil
C
4

When the running container is issued with the docker pause command, the SIGSTOP signal is passed which allows the processes inside the container (basically the container itself) to be in a paused state. So when the docker unpause is issued, SIGCONT signal is passed to the container processes to restore the container proceses.

When the docker stop command is issued to the running container, the SIGTERM signal is passed to the container processes to stop and stops the container.

Hence when the docker pause is issued to a container, and the docker service is restarted, the cgroups allocated to it is released. (as the SIGTERM is passed to all the container processes) So after the restart, the unpause would not be helpful as the containers are stopped.

Chauvinism answered 24/7, 2019 at 6:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.