Difficulty: Intermediate
What do docker pause and docker unpause do, and how is pausing different from stopping a container?
docker pause freezes every process in a container using the Linux cgroup freezer, so they stop getting CPU time but stay in memory exactly where they were. docker unpause thaws them and they continue from the same instruction, unaware anything happened. Nothing is signalled, killed or restarted, which makes it very different from docker stop.
Each container has its own cgroup. Pausing writes to the freezer control (freezer.state on cgroup v1, cgroup.freeze on cgroup v2, which all modern distros use). The kernel then removes every task in that cgroup from scheduling atomically. Because it is done by the kernel and not with a signal, processes cannot catch, block or even notice it. Contrast this with sending SIGSTOP to each process: that is visible to parent processes and racy when processes are forking.
pause | stop | kill | |
|---|---|---|---|
| Mechanism | cgroup freezer | SIGTERM, then SIGKILL | SIGKILL |
| Process memory | Kept in RAM | Released | Released |
| Resumes from | Exact same point | Fresh start of the CMD | Fresh start of the CMD |
Status in docker ps | Up ... (Paused) | Exited (0) | Exited (137) |
| CPU used while in state | None | None | None |
docker commit pauses the container by default while it captures the filesystem, so files are not changing mid-copy. You can pause manually before copying data out with docker cp.docker exec into a paused container; unpause it first.docker run -d --name counter alpine sh -c 'i=0; while true; do echo $i; i=$((i+1)); sleep 1; done'
docker pause counter
docker ps --filter name=counter --format '{{.Names}}: {{.Status}}'
docker stats --no-stream counter # CPU shows 0%
docker exec counter echo hi # fails while paused
docker unpause counter
docker logs --tail 3 counter # counter continues, no restart from 0
The loop resumes counting from where it froze, which proves the process was suspended rather than restarted.
cgroup freezer, docker pause, Process Suspension, docker commit, SIGSTOP