Pause/Unpause

Difficulty: Intermediate

Question

What do docker pause and docker unpause do, and how is pausing different from stopping a container?

Answer

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.

How the freezer works

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 vs stop vs kill

pausestopkill
Mechanismcgroup freezerSIGTERM, then SIGKILLSIGKILL
Process memoryKept in RAMReleasedReleased
Resumes fromExact same pointFresh start of the CMDFresh start of the CMD
Status in docker psUp ... (Paused)Exited (0)Exited (137)
CPU used while in stateNoneNoneNone

Where pause is actually useful

  • Consistent snapshots. 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.
  • Temporarily freeing CPU. On a shared build server, freeze a heavy batch job while an urgent build runs, then resume it without losing progress.
  • Debugging and testing. Freeze one service to simulate it hanging (not crashing) and see whether your clients have proper timeouts and circuit breakers. This is a cheap form of chaos testing.

Gotchas

  • Memory is not freed. A paused 4 GB container still holds 4 GB. Pause is not a way to save RAM.
  • Network connections stay open but go silent. Clients see timeouts, not refusals. Load balancers keep sending traffic unless health checks fail, and TCP peers or databases may drop the connection if the pause is long.
  • You cannot docker exec into a paused container; unpause it first.
  • Timers jump. After unpausing, the app sees wall-clock time has leapt forward, which can trigger lease expirations or token refreshes.
  • Windows containers support pause only with Hyper-V isolation.
Lifecycle of a paused container. Pausing removes processes from the scheduler without touching their memory.
  1. Container running: Processes are scheduled normally.
  2. docker pause: Docker sets the container's cgroup to frozen.
  3. Frozen: Up (Paused): No CPU used; memory and sockets stay allocated.
  4. docker unpause: Cgroup is thawed by the kernel.
  5. Execution resumes: Processes continue from the exact instruction they stopped at.

Code examples

Pausing and observing a container

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.

Key points

  • pause uses the cgroup freezer; processes are suspended without any signal.
  • Memory stays allocated and network connections stay open while paused.
  • unpause resumes processes from exactly where they stopped.
  • docker commit pauses the container by default for a consistent snapshot.
  • You cannot exec into a paused container.

Common follow-up questions

  • Why is the cgroup freezer better than sending SIGSTOP to every process?
  • What do clients of a paused service experience?
  • How is pausing different from checkpointing with CRIU?
  • Why does docker commit pause the container?

Interview tips

  • Say 'cgroup freezer' explicitly; it is the keyword interviewers wait for.
  • Contrast with stop in terms of memory and resumption point.
  • Give one real use case such as simulating a hung dependency to test timeouts.

Concepts covered

cgroup freezer, docker pause, Process Suspension, docker commit, SIGSTOP

More Docker & Containers questions