Bird
0
0

Which of the following is the correct syntax to add a health check in a Dockerfile for a Spring Boot app that exposes /actuator/health on port 8080?

easy📝 Syntax Q12 of 15
Spring Boot - Docker and Deployment

Which of the following is the correct syntax to add a health check in a Dockerfile for a Spring Boot app that exposes /actuator/health on port 8080?

?
AHEALTHCHECK RUN curl http://localhost:8080/actuator/health
BHEALTHCHECK CMD curl --fail http://localhost:8080/actuator/health || exit 1
CHEALTHCHECK CMD ping localhost:8080/actuator/health
DHEALTHCHECK EXEC curl http://localhost:8080/actuator/health
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct HEALTHCHECK syntax

    The HEALTHCHECK instruction uses CMD followed by a command that returns 0 on success or non-zero on failure.
  2. Step 2: Verify the command tests the health endpoint properly

    Using curl with --fail returns error if the endpoint is unhealthy, triggering Docker restart.
  3. Final Answer:

    HEALTHCHECK CMD curl --fail http://localhost:8080/actuator/health || exit 1 -> Option B
  4. Quick Check:

    HEALTHCHECK CMD + curl --fail = correct syntax [OK]
Quick Trick: Use HEALTHCHECK CMD with curl --fail for health endpoint [OK]
Common Mistakes:
  • Using RUN instead of CMD in HEALTHCHECK
  • Using ping instead of curl for HTTP check
  • Using EXEC keyword which is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes