How to disable auto-restart on a Docker container
Codemia Knowledge Hub ·
Run docker update --restart no <container>. It changes the restart policy of an existing container, running or stopped, without stopping and recreating it. For new containers you can pass --restart no to docker run, though that is already the default when no restart policy is given.
The four restart policies
Restart policies control what happens when a container exits. You set them with --restart on docker run and change them later with docker update.
| Policy | Restarts on crash | Restarts on docker stop | Restarts on daemon restart | Default |
no | No | No | No | Yes |
always | Yes | No (but resumes after daemon restart) | Yes | No |
unless-stopped | Yes | No | Only if not manually stopped | No |
on-failure[:N] | Yes (if exit code is non-zero) | No | No | No |
The difference between always and unless-stopped shows up when the Docker daemon restarts, for example after a reboot. A container with always comes back even if you ran docker stop before the reboot. A container with unless-stopped stays stopped if you stopped it manually. People often pick always thinking it means "keep running until I stop it"; if manual stops should survive reboots, use unless-stopped.
Changing the policy on an existing container
docker update changes a container's configuration in place, which has been possible since Docker 1.11. Older tutorials that tell you to stop, remove and recreate the container predate it.
Check that the change took effect:
Expected output:
This works on both running and stopped containers.
Several containers at once
Pass multiple names or IDs:
Every running container:
All containers, including stopped ones:
New containers with docker run
Without --restart, docker run uses no. Stating it explicitly is unnecessary but can make scripts and documentation clearer:
Docker Compose: quote "no"
In Compose files the policy is the restart key. Leave it out (the default is no) or set it explicitly:
The quotes matter. Unquoted no is parsed by YAML as boolean false, which is not a valid restart policy and is a common source of parse errors and unexpected behavior.
To change the policy of a running Compose service without recreating it:
Or recreate the service with the updated file:
Checking the current policy
For a cleaner overview:
on-failure with a retry limit
on-failure takes an optional maximum retry count. Once the limit is reached, Docker stops restarting the container. It sits between always, which can cause restart loops, and no, which offers no resilience.
A container that hits its limit stays down silently. If you are working out why a container is not running, check its restart count and exit code with docker inspect. Fix the underlying problem, then restart it manually. The counter resets if you docker stop and docker start the container.
Swarm and Kubernetes manage restarts themselves
Docker restart policies apply to standalone containers only.
Docker Swarm uses service-level restart policies from the deploy section of a Compose file. docker update --restart does not apply to Swarm services; update the service instead:
Kubernetes uses the Pod restartPolicy field, which accepts Always, OnFailure or Never. Docker-level restart policies are ignored for containers running in Kubernetes pods.
Related reading
- Docker - library initialization failed - unable to allocate file descriptor table - out of memory
- Docker - Name is already in use by container
- Docker - Override or remove ENTRYPOINT from a base image
- Docker - Postgres and pgAdmin 4 Connection refused
- Docker Add a restart policy to a container that was already created
- Docker adding a file from a parent directory
- Docker - Ubuntu - bash ping command not found
- Docker - Unable to locate package docker-engine
System design interview problems on this topic
- Design a Container Orchestration System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design GitHub Actions: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.