Bird
0
0

A developer wrote this Dockerfile snippet for a Spring Boot app:

medium📝 Debug Q6 of 15
Spring Boot - Docker and Deployment
A developer wrote this Dockerfile snippet for a Spring Boot app:
FROM openjdk:17-jdk-slim
COPY target/app.jar /app.jar
CMD java -jar /app.jar

Why might this container fail to start?
AThe jar file must be renamed to app.war
BThe COPY command is missing the source path
CThe CMD instruction should be an array, not a string
DThe base image openjdk:17-jdk-slim is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check CMD syntax in Dockerfile

    CMD should be an array for exec form to avoid shell issues, e.g., ["java", "-jar", "/app.jar"]
  2. Step 2: Verify other instructions

    COPY has correct source and destination; base image is valid; jar extension is correct.
  3. Final Answer:

    The CMD instruction should be an array, not a string -> Option C
  4. Quick Check:

    Docker CMD syntax = Use array form [OK]
Quick Trick: Use array syntax for CMD to avoid shell errors [OK]
Common Mistakes:
  • Using string form CMD causing startup failure
  • Misunderstanding COPY source/destination
  • Thinking base image is invalid
  • Confusing jar and war extensions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes