Bird
0
0

Identify the error in this Dockerfile snippet for a multi-stage build:

medium📝 Debug Q14 of 15
Spring Boot - Docker and Deployment
Identify the error in this Dockerfile snippet for a multi-stage build:
FROM openjdk:17 AS builder
WORKDIR /app
COPY . .
RUN ./mvnw package

FROM openjdk:17-jdk-slim
COPY /app/target/app.jar /app/app.jar
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
AThe first stage should use a Maven image, not openjdk.
BThe ENTRYPOINT syntax is incorrect and will cause a runtime error.
CThe WORKDIR command is missing in the second stage.
DThe COPY command in the second stage uses an absolute path instead of a relative path from the builder stage.
Step-by-Step Solution
Solution:
  1. Step 1: Check COPY command in second stage

    The COPY command uses '/app/target/app.jar' which is an absolute path on the host, not from the builder stage.
  2. Step 2: Correct COPY syntax for multi-stage

    It should be 'COPY --from=builder /app/target/app.jar /app/app.jar' to copy from the builder stage.
  3. Final Answer:

    The COPY command in the second stage uses an absolute path instead of a relative path from the builder stage. -> Option D
  4. Quick Check:

    Use COPY --from=builder for multi-stage files [OK]
Quick Trick: Use COPY --from=stage to copy files between stages [OK]
Common Mistakes:
  • Forgetting --from=builder in COPY
  • Assuming ENTRYPOINT syntax is wrong
  • Thinking WORKDIR is required in second stage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes