9

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

Alex J
  • 3,085
  • 3
  • 19
  • 29

1 Answers1

11

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.

BMitch
  • 231,797
  • 42
  • 475
  • 450