A home server’s containers are supposed to come back on their own: after a crash, after a reboot, after a Docker update. Whether they do depends on one flag, --restart, and on two details most people learn by surprise: what counts as “stopped,” and what happens when the Docker daemon itself restarts. To see each policy’s behavior rather than paraphrase it, containers were crashed on purpose, stopped, killed, and left running while the daemon was shut down and started again. The tests ran on a Docker daemon in an Ubuntu 24.04 sandbox with a minimal busybox image.
The four policies
What Docker’s documentation says
Docker’s guide to starting containers automatically lists four values. no never restarts the container and is the default. on-failure[:max-retries] restarts it only when it exits with a non-zero code, optionally up to a limit. always restarts it whenever it stops; if it was manually stopped, it is restarted only when Docker daemon restarts or when the container is manually restarted. unless-stopped is like always, except that a container that was stopped is not restarted even after the daemon restarts.
The flag
docker run -d --restart unless-stopped myimage
In a Compose file the same setting goes under each service as restart: unless-stopped.

Test one: a container that keeps crashing
The setup
Four containers ran the same command: print a line, sleep one second, exit with code 1. Each had a different policy. Thirty seconds later:
rp-no exited restarts=0 exit=1
rp-on-failure3 exited restarts=3 exit=1
rp-always restarting restarts=8 exit=1
rp-unless-stopped restarting restarts=8 exit=1
The no container died once and stayed dead. on-failure:3 tried exactly three more times and then gave up, leaving the container exited. The other two were still cycling.
The backoff, measured
Docker does not restart a crashing container instantly forever. The docker run reference says an increasing delay is added before each restart, double the previous delay, starting at 100 milliseconds, up to a maximum of one minute. Timing the gap between each exit and the next start from docker events gave:
0.19, 0.25, 0.43, 0.86, 1.63, 3.23, 6.46 seconds
From the third restart on, each gap is almost exactly double the last, matching the documented 100, 200, 400, 800 ms pattern plus a little overhead for starting the container. Carried forward, the delay would reach 51.2 seconds by the tenth restart and then sit at the one-minute ceiling.
How many restarts an hour
Working the documented schedule forward shows how fast a broken container settles into a slow rhythm:
| Restart | Delay before it | Time spent waiting so far |
|---|---|---|
| 1 | 0.1 s | 0 s |
| 5 | 1.6 s | 1.5 s |
| 8 | 12.8 s | 12.7 s |
| 10 | 51.2 s | 51.1 s |
| 11 on | 60 s (cap) | 102 s and up |
After roughly ten tries in under two minutes, a container that keeps failing is retried about once a minute, around 60 times an hour, until someone fixes it or stops it. With on-failure:N it simply stops after N tries.
When the delay resets
The same reference says that if a container is started and runs for at least 10 seconds, the delay resets to 100 ms. A service that crashes once a day therefore restarts almost immediately each time; one that crashes every few seconds is slowed down to once a minute, which keeps a broken container from hammering the machine.
Test two: on-failure and a clean exit
Exit code 0
A container with --restart on-failure that slept one second and exited with code 0 was not restarted. That matches the documentation: on-failure only acts on a non-zero exit code. A one-shot job that finishes successfully stays finished.
An out-of-memory kill
A container limited to 32 MB of memory ran a loop that doubled a string until memory ran out, with --restart on-failure:2:
oom status=exited restarts=2 exit=137 oomkilled=true
Exit code 137 is non-zero, so on-failure treated the kill as a failure and restarted it twice before giving up. The OOMKilled field in docker inspect showed why. A container that keeps getting restarted with exit 137 is usually out of memory, not crashing on its own.

Test three: stop, kill and the daemon restart
Manual stops are respected, for now
Two long-running containers, one always and one unless-stopped, were stopped with docker stop. A third always container was stopped with docker kill. None of them restarted. The documentation explains that if a container is manually stopped, the restart policy is ignored until the Docker daemon restarts or the container is manually restarted. The test showed docker kill counts as a manual stop too: the always container sat exited.
Then the daemon restarted
The Docker daemon was shut down with several containers in different states and started again. The result:
| Container | Policy | State before | After daemon restart |
|---|---|---|---|
| rs-always | always | stopped with docker stop | running |
| rs-always-running | always | stopped with docker kill | running |
| rs-unless | unless-stopped | stopped with docker stop | exited |
| rs-unless-running | unless-stopped | running | running |
| rs-no-running | no | running | exited |
This is the whole difference between always and unless-stopped. A container someone deliberately stopped comes back after a reboot or Docker update under always, and stays down under unless-stopped. And a container with no policy, even one that was running happily, does not come back at all after the daemon restarts.
Starting it again re-arms the policy
The other way back, besides a daemon restart, is starting the container by hand. An always container was stopped with docker stop, started again with docker start, and then its main process was killed from outside Docker with kill -9, the way a crash would end it. Three seconds later it was running again with a restart count of 1. The manual start had switched the policy back on; only the deliberate stop had suspended it.
An unhealthy container is not restarted
A last test checked a common assumption: that a container failing its health check will be restarted. A container was given --restart always and a health check that always failed (--health-cmd false, every 2 seconds, unhealthy after 2 failures). Twenty-four seconds later, docker ps showed it as Up 24 seconds (unhealthy), with a restart count of 0. Restart policies react to the container’s main process exiting, nothing else. A process that hangs while still running, which is exactly what health checks exist to catch, is marked unhealthy and left alone. Acting on that status takes something else: an orchestrator, a watchdog container, or the application exiting on its own when it detects it is stuck.
Changing a policy on an existing container
No need to recreate
Unlike logging options, a restart policy can be changed in place:
docker update --restart unless-stopped rs-no-running
docker inspect immediately showed the new policy. That makes it easy to fix a container that was started without one, which is common for anything first launched with a quick docker run while testing.
The 10-second rule
The guide also says a restart policy only takes effect after a container starts successfully, defined as staying up for at least 10 seconds while Docker monitors it, to stop a container that never starts from looping. The crash test above did not show that: the one-second containers were restarted from the first exit. What the test did show is the backoff doing the job that sentence describes, stretching the gaps until a hopeless container is retried only once a minute. Anyone relying on that 10-second rule should test it on their own Docker version.

Choosing a policy
For most home-server services: unless-stopped
A web app, a database, a media server or a DNS filter should come back after a crash and after a reboot, but should stay off if someone turned it off on purpose for maintenance. That is unless-stopped. It is the policy most often recommended for long-running self-hosted services for exactly that reason.
When always fits
always is for containers that must be running no matter what, where a person stopping it and forgetting to start it again would be worse than an unexpected restart after a reboot.
When on-failure fits
on-failure, usually with a retry limit, suits batch jobs and scripts that should retry a few times on error but must not be restarted after they finish successfully. no remains right for anything run by hand.
One more check
A restart policy only matters if the Docker daemon itself starts at boot. On systemd machines that is the docker service being enabled, covered in the earlier post on systemctl enable versus start. The earlier post on Docker log limits is worth reading alongside this one: a container in a restart loop writes a fresh burst of startup logs every time.
Sources
- Start containers automatically, Docker Docs: https://docs.docker.com/engine/containers/start-containers-automatically/
- docker container run reference (restart policies), Docker Docs: https://docs.docker.com/reference/cli/docker/container/run/
