In the docker swarm v3 docs, there are 3 different restart policy conditions that can be used. It's obvious what the none
condition does, but I was wondering what the difference between on-failure
and any
is specifically.
Here's a picture from the docs:
$ docker run -d --restart unless-stopped redis. This command changes the restart policy for an already running container named redis . $ docker update --restart unless-stopped redis. And this command will ensure all currently running containers will be restarted unless stopped.
no: Containers will not restart automatically. on-failure[:max-retries]: Restart the container if it exits with a non-zero exit code and provide a maximum number of attempts for the Docker daemon to restart the container.
If you're application is able to detect issues, you can easily have the container restart itself. The two important things are the --restart flag and that the application exists when it detects an issue. With the restart policy, you control what Docker does when the command exists.
Docker Swarm is not being deprecated, and is still a viable method for Docker multi-host orchestration, but Docker Swarm Mode (which uses the Swarmkit libraries under the hood) is the recommended way to begin a new Docker project where orchestration over multiple hosts is required.
The on-failure
policy handles any time a container exist with a non-zero code. The any
policy covers any other scenarios, but may only be handled on daemon restart depending on how the container was stopped (e.g. intentionally stopping a container with docker stop
does not result in an immediate restart).
See this documentation for more details: https://docs.docker.com/config/containers/start-containers-automatically/
Note: I do not recommend a restart policy for containers running within swarm mode. I've seen scenarios, e.g. host out of memory, where both swarm mode and the docker engine attempt to restart the container and it's best to let swarm mode recreate a new container, possibly on another host.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With