0
0
Dockerdevops~20 mins

Health checks in Compose in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Health Check Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Health check status output in Docker Compose
Given this Docker Compose service with a health check, what will be the output of docker-compose ps after the container starts and the health check passes?
Docker
services:
  web:
    image: nginx
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost"]
      interval: 10s
      timeout: 5s
      retries: 3
Aweb docker-entrypoint.sh nginx - Up (unhealthy)
Bweb docker-entrypoint.sh nginx - Up (healthy)
Cweb docker-entrypoint.sh nginx - Up (starting)
Dweb docker-entrypoint.sh nginx - Exited (0)
Attempts:
2 left
💡 Hint
Think about what the health check does and how Docker reports container health.
🧠 Conceptual
intermediate
1:30remaining
Purpose of health checks in Docker Compose
What is the main purpose of defining a health check in a Docker Compose service?
ATo expose the container's ports to the host
BTo automatically restart the container if it crashes
CTo limit the container's CPU and memory usage
DTo monitor if the container's application is working correctly
Attempts:
2 left
💡 Hint
Think about what health means for a running service.
Configuration
advanced
2:30remaining
Correct health check syntax in Docker Compose
Which of these Docker Compose health check configurations is syntactically correct and will run a command every 30 seconds with a 10-second timeout?
A
healthcheck:
  test: ["CMD", "curl", "-f", "http://localhost"]
  interval: 30s
  timeout: 10s
B
healthcheck:
  test: curl -f http://localhost
  interval: 30s
  timeout: 10s
C
healthcheck:
  test: curl -f http://localhost
  interval: 30
  timeout: 10
D
healthcheck:
  test: ["curl", "-f", "http://localhost"]
  interval: 30s
  timeout: 10s
Attempts:
2 left
💡 Hint
The test command must be an array starting with CMD for Compose health checks.
Troubleshoot
advanced
2:00remaining
Diagnosing failing health checks in Compose
You have a health check in Compose that always reports 'unhealthy'. Which command helps you see the detailed health check logs for the container?
Adocker-compose logs --follow
Bdocker-compose ps
Cdocker inspect --format='{{json .State.Health}}' <container_id>
Ddocker stats <container_id>
Attempts:
2 left
💡 Hint
You want to see the health check results stored in container state.
🔀 Workflow
expert
3:00remaining
Using health checks to control service startup order
In Docker Compose, how can you ensure that a service app starts only after the db service is healthy?
AUse <code>depends_on:</code> with <code>condition: service_healthy</code> for <code>app</code> on <code>db</code>
BUse <code>depends_on:</code> with <code>condition: service_started</code> for <code>app</code> on <code>db</code>
CStart <code>db</code> manually before <code>app</code> using separate commands
DSet <code>restart: always</code> on <code>app</code> service
Attempts:
2 left
💡 Hint
Compose supports waiting for health status in depends_on since version 3.4.