30

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
  • 1,807
  • 1
  • 15
  • 33
ibodi
  • 994
  • 2
  • 16
  • 32

4 Answers4

37

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,231
  • 7
  • 13
  • 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
  • 1
    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
7

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 release the memory used after the container is stopped.

This table has even more details.

faboulaws
  • 1,259
  • 11
  • 15
3

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
  • 252,575
  • 45
  • 248
  • 283
0

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
  • 1
  • 1