Docker & ContainersVI · Container LifecycleInterrupting a container
stop, kill, and pause — the three ways to interrupt a container
What you'll learn
- Trace the full `docker stop` path from API call to SIGKILL
- Determine which stop timeout applies when several are configured
- Use STOPSIGNAL and `docker kill -s` deliberately rather than by accident
- Explain what `docker pause` freezes and what it does not
Prerequisites
Verified against Docker Engine 29.x · Docker Engine 28.x · Docker Compose 2.x · containerd 2.x · runc 1.2.x · BuildKit 0.20+ · Linux kernel 5.15+ · Ubuntu 24.04 LTS · Debian 12 (Bookworm) · 2026-08-11
There are three commands that interrupt a running container and they are not
interchangeable. docker stop asks. docker kill tells. docker pause
freezes without asking or telling anybody, including the application.
Choosing the wrong one is how deploys drop in-flight requests, how database containers come back needing recovery, and how a “quick pause for a snapshot” turns into a client-visible hang.
The stop path, step by step
Step 3 is where most surprises live. The signal goes to PID 1 and nowhere
else. If your entrypoint is a shell script that launched the real application
in the background, the shell receives SIGTERM and the application does not.
If PID 1 is a shell without a trap, the signal is discarded entirely,
because Linux does not deliver an unhandled signal to PID 1 of a namespace.
Step 6 is where data is lost. SIGKILL cannot be caught, blocked, or ignored. Whatever the process was doing — a partially written file, an open transaction, an unflushed buffer — stops mid-instruction.
Which timeout wins
Three places can set a stop timeout, and they are consulted in this order:
| Source | Set at | Beats |
|---|---|---|
docker stop -t 60 web | Invocation | Everything |
--stop-timeout 30 on docker create / docker run | Container creation | The default |
| Nothing | — | Defaults to 10 seconds |
There is no STOPTIMEOUT instruction in a Dockerfile — the image can set the
stop signal but not the stop timeout. Compose has stop_grace_period,
which sets the container’s stop timeout at creation.
$ docker inspect --format 'signal={{.Config.StopSignal}} timeout={{.Config.StopTimeout}}' websignal= timeout=<nil>Illustrative output
Empty and <nil> mean “not configured, use the defaults”: SIGTERM and 10
seconds. This is the single most useful pre-deploy check on a stateful
container, because the default 10 seconds is far too short for most databases
and message brokers.
STOPSIGNAL and --stop-signal
Some applications shut down cleanly on something other than SIGTERM. nginx
treats SIGQUIT as “graceful shutdown, finish current requests” and SIGTERM
as “fast shutdown, drop them”. That distinction is exactly what you want
control over during a deploy.
FROM nginx:1.27
STOPSIGNAL SIGQUIT
or, without changing the image:
docker run -d --name web --stop-signal SIGQUIT --stop-timeout 60 nginx:1.27Recent Docker CLI versions also accept --signal on stop and restart,
which overrides the configured stop signal for that one invocation:
docker stop --signal SIGQUIT --timeout 60 webIf your CLI does not have that flag, set --stop-signal at create time
instead — the per-container setting has been there far longer.
kill is not “stop harder”
docker kill sends one signal, immediately, with no timer and no fallback.
Its default is SIGKILL, which is why people think of it as the violent
option, but -s makes it the general-purpose signalling tool:
docker kill --signal SIGHUP webCommon uses that have nothing to do with killing:
SIGHUP— reload configuration, for daemons that implement it.SIGUSR1— reopen log files (nginx), dump goroutine stacks (some Go services), toggle debug logging.SIGUSR2— application-defined; often a live binary upgrade.
pause is a kernel freeze
docker pause does not signal anything. On cgroup v2 it writes 1 to the
container’s cgroup.freeze file, and the kernel stops scheduling every task
in that cgroup. On cgroup v1 it used the freezer controller for the same
effect.
# cat /sys/fs/cgroup/system.slice/docker-25fb9c8b983b.scope/cgroup.freeze0Illustrative output
What that means in practice:
- Memory is untouched. Every page the process had is still resident. A paused container frees no RAM.
- Sockets stay open. The listening socket is still bound, so the kernel keeps accepting connections into the backlog. Clients do not get “connection refused” — they connect successfully and then wait forever. This is worse than a stop for anything behind a load balancer, because the health of the TCP handshake is what most simple health checks measure.
- Timers do not fire. Application-level heartbeats, cluster keepalives, and lease renewals all stop. A paused node in a clustered application gets evicted from the cluster while looking perfectly healthy at the TCP layer.
- Nothing is flushed. The application has no idea it was paused, so it cannot checkpoint, flush a write-ahead log, or close a transaction.
A paused process cannot run a signal handler, because it is not being
scheduled at all. So the graceful half of docker stop is meaningless while
a container is paused: unpause it first, then stop it.
docker unpause web
docker stop --timeout 60 webChoosing between them
| You want to | Use | Why |
|---|---|---|
| Deploy a new version | docker stop with a sized timeout | The application drains |
| Reload configuration | docker kill -s HUP, or the app’s own CLI | No downtime |
| End a runaway process now | docker kill | No negotiation |
| Stop CPU consumption briefly | docker pause | Memory and sockets preserved |
| Recover a wedged container | docker kill then investigate | A stop will just wait out the timeout |
Knowledge check
Knowledge check · 4 questions
Q1. A container was created with `--stop-timeout 30` and you run `docker stop -t 60 web`. How long does the daemon wait before SIGKILL?
Q2. Which processes receive the stop signal when you run `docker stop`?
Q3. A paused container releases its memory back to the host while it is paused.
Q4. A container exits with code 137 immediately after `docker stop`. Which explanations are consistent with that? Select all that apply.
Passing score: 75%. Answers are checked in this browser.