Bird
0
0

You wrote this Dockerfile snippet:

medium📝 Debug Q6 of 15
Spring Boot - Docker and Deployment
You wrote this Dockerfile snippet:
FROM maven:3.8.6-openjdk-17 AS builder
WORKDIR /app
COPY . .
RUN mvn package

FROM openjdk:17-jdk-slim
COPY /app/target/app.jar /app/app.jar
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
The build fails with 'COPY failed: stat /app/target/app.jar: no such file or directory'. What is the error?
AMaven package command failed silently
BCOPY source path is incorrect; should use --from=builder
CENTRYPOINT syntax is invalid
DWORKDIR is missing in second stage
Step-by-Step Solution
Solution:
  1. Step 1: Identify COPY source in second stage

    The COPY command tries to copy from local /app/target/app.jar, which does not exist in second stage context.
  2. Step 2: Correct usage for multi-stage copy

    Must specify --from=builder to copy from build stage's filesystem.
  3. Final Answer:

    COPY source path is incorrect; should use --from=builder -> Option B
  4. Quick Check:

    COPY without --from in multi-stage = error [OK]
Quick Trick: Use COPY --from=builder to access build stage files [OK]
Common Mistakes:
  • Forgetting --from=builder in COPY
  • Assuming files persist between stages without COPY
  • Ignoring build errors in Maven package

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes