docker run --restart picks no, on-failure, always or unless-stopped
Answer: Restart policies control whether containers start automatically when they exit or when Docker restarts. Set one with docker run --restart=VALUE; the default is no. Docker recommends restart policies over process managers for starting containers.
The four values
| Value | Description | |---|---| | no | Don't automatically restart the container (default). | | on-failure[:max-retries] | Restart if it exits due to an error (non-zero exit code); optionally limit retries. A daemon restart does not restart the container. | | always | Restart the container whenever it stops. If manually stopped, it's restarted only when the Docker daemon restarts or the container is manually restarted. | | unless-stopped | Like always, except that a stopped container isn't restarted even after the Docker daemon restarts. |
docker run -d --restart unless-stopped redis
docker run -d --restart on-failure:5 myjob
Details
- A restart policy only applies once a container has started successfully: up for at least 10 seconds, with Docker monitoring it. That keeps a container that never starts from a restart loop.
- Restart policies are different from the
--live-restoreflag ofdockerd, which keeps containers running during a Docker upgrade.
See also
Claims
- id: C1 claim: Restart policies control automatic restarts on exit or daemon restart. source: S1 evidence: "restart policies to control whether your containers start automatically when they exit"
- id: C2 claim: on-failure does not restart the container when the daemon restarts. source: S1 evidence: "It doesn't restart the container if the daemon restarts."
- id: C3 claim: unless-stopped does not restart a stopped container after daemon restarts. source: S1 evidence: "it isn't restarted even after Docker daemon restarts"
- id: C4 claim: The --restart flag sets a container's restart policy. source: S2 evidence: "Use the --restart flag to specify a container's"
Sources
- [S1] Start containers automatically. Docker docs (Engine). https://docs.docker.com/engine/containers/start-containers-automatically/ . License: Apache-2.0. Accessed 2026-11-18.
- [S2] docker container run. Docker docs (CLI reference). https://docs.docker.com/reference/cli/docker/container/run/ . License: Apache-2.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker docs (Engine), Start containers automatically; Docker docs (CLI reference), docker container run. Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker docs (Engine), Start containers automatically; Docker docs (CLI reference), docker container run. Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc.
Cite this
iinventedlight. 2026. "docker run --restart picks no, on-failure, always or unless-stopped." iinventedlight Library, iil:note:xw6zdwz1, version of 2026-11-18. https://iinventedlight.com/library/notes/docker-restart-policies/. License: CC-BY-4.0.
@misc{iil_note_xw6zdwz1,
author = {{iinventedlight}},
title = {{docker run --restart picks no, on-failure, always or unless-stopped}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/docker-restart-policies/},
note = {Permanent ID iil:note:xw6zdwz1. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- docker-restart-policies.table.json (table; CC-BY-4.0)
- docker-restart-policies.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-restart-policies.md.