This quiz explores key concepts of service restart policies in Docker Compose, focusing on correct configuration, available options, and their impact on container behavior. Enhance your expertise in managing container reliability and automated recovery using restart strategies.
What will happen if you set 'restart: always' for a service in your Docker Compose file and manually stop the container using a command?
Explanation: 'restart: always' causes the container to restart on failure or daemon restart, but not after a manual stop. If you manually stop the container, it is assumed intentional and will not be restarted automatically. The first option incorrectly claims containers always restart after stopping, which is not true for manual stops. Options three and four wrongly limit restarts to only reboots or error codes, which does not fully reflect the policy's behavior.
When configuring restart policies in Docker Compose, which setting will restart a container only if it exits with a non-zero status?
Explanation: The 'on-failure' policy only restarts containers that exit with errors (non-zero exit codes), making it suitable for error recovery scenarios. 'always' restarts containers regardless of the exit status, while 'unless-stopped' behaves like 'always' except for manual stops. 'restart-on-exit' is not a valid policy, making it an incorrect choice.
Which of the following is the correct way to specify a restart policy in a docker-compose.yml file for the 'web' service?
Explanation: The valid format in a Compose file is 'restart: [policy]', such as 'restart: always'. 'restart_policy' and 'policy' are not recognized keys in Compose. 'restart = unless-stopped' uses an incorrect syntax with both the equal sign and the policy name.
If a service has 'restart: unless-stopped' set in the Compose file, what will occur after a system reboot if the container was not manually stopped before the reboot?
Explanation: 'unless-stopped' ensures that the container restarts on daemon or system restarts if it was running before. It only prevents auto-restart if you manually stopped the container. The second and third options incorrectly claim no or only manual restart occurs. The fourth option confuses it with the 'on-failure' policy, which is not accurate for 'unless-stopped'.
Which of the following values is not a valid restart policy in Docker Compose?
Explanation: 'auto' is not recognized as a valid restart policy in Compose. 'on-failure', 'never', and 'unless-stopped' are all supported and well-documented restart policy values. Selecting 'auto' would result in a configuration error, while the other options are accepted and work as intended.