Bird
0
0

You wrote this Dockerfile snippet but the health check is not working as expected:

medium📝 Troubleshoot Q14 of 15
Docker - Logging and Monitoring
You wrote this Dockerfile snippet but the health check is not working as expected:
HEALTHCHECK CMD curl http://localhost/ || exit 1
What is the likely problem?
AHealth check commands cannot use curl
BUsing CMD instead of RUN in HEALTHCHECK
CThe exit code should be 0 on failure
DMissing the '-f' flag in curl to fail on HTTP errors
Step-by-Step Solution
Solution:
  1. Step 1: Understand curl behavior in health checks

    Without '-f', curl returns success even on HTTP errors, so health check may falsely pass.
  2. Step 2: Identify correct fix

    Adding '-f' makes curl fail on HTTP errors, correctly marking container unhealthy.
  3. Final Answer:

    Missing the '-f' flag in curl to fail on HTTP errors -> Option D
  4. Quick Check:

    Use curl -f to detect HTTP failures in health checks [OK]
Quick Trick: Add '-f' to curl for proper failure detection [OK]
Common Mistakes:
  • Confusing CMD with RUN in HEALTHCHECK
  • Thinking curl cannot be used in health checks
  • Using exit 0 to indicate failure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes