Bird
0
0

You have a Docker Compose file with this service:

medium📝 Troubleshoot Q14 of 15
Docker - Production Patterns
You have a Docker Compose file with this service:
web:
  image: myapp:latest
  restart: on-failure
  healthcheck:
    test: curl -f http://localhost/health || exit 1
    interval: 1m
    retries: 3

The container keeps restarting even though the app is healthy. What is the likely cause?
AThe restart policy triggers on container exit, not health check failure.
BThe health check command syntax is invalid and causes failure.
CThe interval is too long, so health checks are ignored.
DDocker Compose does not support health checks.
Step-by-Step Solution
Solution:
  1. Step 1: Understand restart policy behavior

    'restart: on-failure' restarts containers only if they exit with an error, not based on health check status.
  2. Step 2: Analyze health check impact

    Health check failures mark container unhealthy but do not cause restarts. If container restarts, it likely exited unexpectedly.
  3. Final Answer:

    The restart policy triggers on container exit, not health check failure. -> Option A
  4. Quick Check:

    Restart on-failure = restart on exit only [OK]
Quick Trick: Restart on-failure restarts only on exit, not health check [OK]
Common Mistakes:
  • Confusing health check failure with container exit
  • Assuming Docker Compose ignores health checks
  • Misreading health check syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes