Pcornel
Browse topics
Options
Recent
Favorites
Containers · Technical reference

Container Restart Policies

Direct answer

Restart policies decide whether the runtime restarts a container when it exits: Docker no, on-failure, always, unless-stopped; Kubernetes pods use restartPolicy with backoff.

When to use this

Use it to keep services running, or when a container restarts in a loop.

First 30 seconds

1. docker inspect <c> --format '{{.HostConfig.RestartPolicy}} {{.RestartCount}}'.

2. Exit code of the last run.

3. Logs of the previous run.

4. Fix the crash cause.

5. Set unless-stopped/always for services.

Operational verification

container exits → policy decides → restart with backoff

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Docker / containerd / Podman / Kubernetes / OCI-compatible platforms
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformDocker / containerd / Podman / Kubernetes / OCI-compatible platforms
Scope / prerequisiteUse it to keep services running, or when a container restarts in a loop.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 How to verify Verify boundary

Reboot the host (or restart the daemon) in a test and confirm the container comes back. For loops, read the exit code: 137 usually means killed (often OOM), 1 an application error.

Step 2 Common failures Narrow the fault

Policy always also restarts containers you stopped once the daemon restarts. A container that exits 0 is not restarted by on-failure. Docker restart policies do not replace a process supervisor for health; a hung process is not restarted.

Key points

Restarts hide crashes — monitor restart counts and logs. Kubernetes restarts with exponential backoff (CrashLoopBackOff).

Key checks
  • docker ps -a — containers and exit codes
  • docker logs <c> — container output
  • docker inspect <c> — config, mounts, network, state
ReferenceWhat it is1 section · depth on demand

How it works

The daemon tracks each container's policy and restarts it with increasing delay after repeated failures. Restart policies act only on containers managed by the daemon; Compose sets them from restart: in compose.yaml.

ReferenceImportant terms & boundaries3 sections · depth on demand

Policies

PolicyRestarts when
noNever
on-failure[:N]Exit code ≠ 0 (max N times)
alwaysAlways, also after daemon restart
unless-stoppedAlways, except if stopped manually
docker update --restart unless-stopped web
docker inspect -f '{{.RestartCount}} {{.State.ExitCode}}' web

Documented example, not captured output. In Kubernetes, Pod restartPolicy and the kubelet's back-off handle restarts.

In depth

Restart policies are handled by the Docker daemon. After repeated failures the daemon waits longer between restarts (starting at 100 ms and doubling), and a container must run for at least 10 seconds before the restart counts as successful and the delay resets.

Choosing a policy

WorkloadPolicyReason
Long-running serviceunless-stoppedComes back after reboot, but respects a manual stop
Batch job that may failon-failure:5Retries errors, gives up after 5 attempts
One-off tasknoA finished task should stay finished
Must always run, even after manual stop + rebootalwaysRarely what you want

Exit codes tell you why it restarted

docker inspect -f '{{.RestartCount}} {{.State.ExitCode}} {{.State.OOMKilled}} {{.State.Error}}' api
# 14 137 true   → killed by the memory limit, restarted 14 times
Exit codeMeaning
0Clean exit — not restarted by on-failure
1, 2 …Application error
125 / 126 / 127Docker could not run / not executable / command not found
137SIGKILL (OOM or docker kill)
143SIGTERM (normal stop)

Health checks do not restart containers

A failing HEALTHCHECK marks the container unhealthy, but plain Docker does not restart it. Swarm services and Kubernetes liveness probes do; otherwise an external watchdog is needed.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • restart: always hiding crash loops.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
container restart policiesdocker restart policyunless-stopped
Confirmation

Confirm action

Continue?