docker - how do you disable auto-restart on a container?
You can use the --restart=unless-stopped
option, as @Shibashis mentioned, or update the restart policy (this requires docker 1.11 or newer);
See the documentation for docker update
and Docker restart policies.
docker update --restart=no my-container
that updates the restart-policy for an existing container (my-container
)
Use the below to disable ALL auto-restarting (daemon) containers.
docker update --restart=no $(docker ps -a -q)
Use the following to disable restart a SINGLE container.
docker update --restart=no the-container-you-want-to-disable-restart
Rational:
Docker provides restart policies to control whether your containers start automatically when they exit, or when Docker restarts. This is often very useful when Docker is running a key service.
Notes
If you are using docker-compose this might be useful to know.
restart no is the default restart policy, and it does not restart a container under any circumstance. When always is specified, the container always restarts. The on-failure policy restarts a container if the exit code indicates an on-failure error.
restart: "no"
restart: always
restart: on-failure
restart: unless-stopped
restart: always
You can start your container with --restart=unless-stopped
.
If you have a swarm restarting the containers, the swarm will restart any containers you stop or rm, irrespective of the restart option. That's a feature, not a bug.
Make sure you are not running a service you forgot about:
docker service ls
Then, you can stop the service
docker service rm <service id discovered with previous command>