Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between docker restart_policy on-failure vs any

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: enter image description here

like image 733
Alex J Avatar asked Jun 12 '19 02:06

Alex J


People also ask

What is restart unless stopped docker?

$ 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.

Does Docker compose restart container on failure?

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.

Can a docker container restart itself?

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.

Is docker swarm mode deprecated?

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.


1 Answers

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.

like image 78
BMitch Avatar answered Oct 20 '22 17:10

BMitch