Questão de Container Orchestration #019e3a4f
Which of these is a valid container restart policy?
On login
On update
On start
On failure
Explicação Oficial / Explicações da Comunidade
Valid Container Restart Policy
A valid container restart policy in Docker is On failure. This policy instructs the container runtime to automatically restart the container if it exits with a non-zero exit code, indicating a failure. Docker supports several restart policies: no (default, never restart), always (always restart regardless of exit status), on-failure (restart only on failure), and unless-stopped (restart unless explicitly stopped).
How It Works
When a container is started with --restart=on-failure, Docker monitors the exit code of the main process. If the process exits with a non-zero code, Docker will attempt to restart the container. The restart attempts follow an exponential backoff strategy to prevent rapid restarts. This policy is useful for services that may crash due to transient errors but should be automatically recovered.
Why the Correct Value is Right
The on-failure policy is explicitly defined in Docker's documentation and command-line interface. It is a standard restart policy that can be set via the --restart flag when running a container or in the restart_policy section of a Docker Compose file. It ensures that containers are restarted only when they fail, not on normal exits.
Why the Incorrect Values are Wrong
- On login: This is not a Docker restart policy. It might be confused with systemd services that can be triggered on user login, but it has no meaning in container orchestration.
- On update: This is not a standard restart policy. While containers can be restarted during updates (e.g., via rolling updates in orchestration tools), it is not a built-in restart policy in Docker.
- On start: This is not a restart policy. Docker containers start when created or started, but the restart policy determines behavior after the container exits, not at initial start.
In summary, only on-failure is a valid container restart policy among the given options.