Deepen your understanding of configuring and utilizing healthchecks in Docker Compose, including syntax, behaviors, and best practices. This quiz helps users assess their skills in ensuring container health within a multi-container orchestration environment.
Which field is required to specify the command executed by a healthcheck in a Docker Compose service, for example: testing if a web server responds on port 80?
Explanation: The 'test' field in the healthcheck section defines the command to run, such as 'curl' to check if a server is responding. The other options are incorrect; 'cmd' is not used in this context, 'verify' and 'probe' are not valid keywords in a Docker Compose healthcheck. Using the wrong field will cause Docker Compose to ignore or misinterpret the healthcheck configuration.
What is the default behavior in Docker Compose if a container's healthcheck fails and the container is marked as unhealthy?
Explanation: When a container becomes unhealthy due to a failed healthcheck, the container continues to run with a status of 'unhealthy'. The container will not be restarted, stopped, or deleted by default. Only certain orchestrators or applications may take further action based on this status; Docker Compose itself leaves the container running unless otherwise managed.
Which healthcheck setting defines how long Docker Compose waits before starting to perform healthchecks on a new container instance?
Explanation: The 'start_period' field configures the initial waiting period before healthchecks begin, giving services like databases time to initialize. 'Interval' specifies how often to perform healthchecks, 'timeout' sets how long to wait for a check to complete, and 'delay' is not part of the standard healthcheck options. Misusing these fields may result in premature or missed healthcheck results.
How can you disable a healthcheck for a specific service in Docker Compose?
Explanation: Setting healthcheck to 'disable' explicitly turns off healthchecks for that service in Docker Compose. While omitting the 'healthcheck' section means no healthcheck is configured, setting it to 'none' or 'false' are not valid syntax and will be ignored. This ensures you have control over whether healthchecking is active for each container.
When using the 'depends_on' option with 'condition: service_healthy' in Docker Compose, what is the effect on service startup order?
Explanation: Setting 'depends_on: condition: service_healthy' ensures that the dependent service will not start until the referenced service's healthcheck reports 'healthy'. If only creation is awaited, it doesn't guarantee the service is ready, while waiting for image downloads or ignoring health status doesn't ensure startup readiness. This option helps coordinate reliable service initialization.