Bird
0
0

Given this Dockerfile snippet for a Spring Boot app:

medium📝 component behavior Q13 of 15
Spring Boot - Docker and Deployment
Given this Dockerfile snippet for a Spring Boot app:
FROM maven:3.8.6-openjdk-17 AS builder
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src ./src
RUN mvn package -DskipTests

FROM openjdk:17-jdk-slim
COPY --from=builder /app/target/myapp.jar /app/myapp.jar
ENTRYPOINT ["java", "-jar", "/app/myapp.jar"]
What will be the size impact of this multi-stage build compared to a single-stage build including Maven?
AThe final image will be smaller because Maven and source files are excluded.
BThe final image will be larger because it contains both Maven and JDK.
CThe final image size is the same as a single-stage build.
DThe final image will fail to build due to missing source files.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze multi-stage build steps

    The first stage builds the app with Maven, the second stage copies only the jar file.
  2. Step 2: Understand image size impact

    Since Maven and source code are not copied to the final image, it is smaller than a single-stage build including Maven.
  3. Final Answer:

    The final image will be smaller because Maven and source files are excluded. -> Option A
  4. Quick Check:

    Copy only jar = smaller image [OK]
Quick Trick: Final image excludes build tools, so it's smaller [OK]
Common Mistakes:
  • Assuming Maven stays in final image
  • Thinking source files are copied to final image
  • Believing multi-stage builds cause build failure here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes