49

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.

Abdulrahman Bres
  • 2,603
  • 1
  • 20
  • 39
ibodi
  • 1,543
  • 3
  • 21
  • 40

5 Answers5

56

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.

Hemant Singh
  • 1,487
  • 10
  • 15
  • 3
    after docker pause, if I restart my laptop, will I manage to continue the process? may be not, right? – grep Jul 17 '19 at 03:47
  • 4
    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. – AL the X Nov 11 '20 at 15:45
12

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.

Antony Hatchkins
  • 31,947
  • 10
  • 111
  • 111
faboulaws
  • 1,909
  • 16
  • 16
12

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!

Mostafa Wael
  • 2,750
  • 1
  • 21
  • 23
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.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
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.

Dr.Mr.Dr
  • 51
  • 3