问题
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:
回答1:
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.
来源:https://stackoverflow.com/questions/56554029/whats-the-difference-between-docker-restart-policy-on-failure-vs-any