Consider a Spring Boot app Dockerfile using multi-stage builds. What is the primary advantage of this approach?
Think about what happens when you separate build tools from the runtime environment.
Multi-stage builds let you compile your app in one stage with all tools, then copy only the needed files to a smaller runtime image. This keeps the final image small and efficient.
Given a multi-stage Dockerfile, which COPY command correctly copies the built jar from the build stage named 'builder'?
Remember the syntax for copying files from a named build stage.
The correct syntax uses --from=builder to copy from the build stage named 'builder'. The source path must match where the jar is built.
Look at this Dockerfile snippet:
FROM maven:3.8.6-openjdk-17 AS builder WORKDIR /app COPY pom.xml . COPY src ./src RUN mvn clean package -DskipTests FROM openjdk:17-jdk-slim COPY --from=builder /app/target/*.jar /app/app.jar ENTRYPOINT ["java", "-jar", "/app/app.jar"]
Why might the container fail to start?
Consider how Docker COPY handles wildcards.
Docker COPY does not expand wildcards like *.jar. You must specify the exact jar filename or rename it during build to a fixed name.
You build two Docker images for the same Spring Boot app:
- Image A uses a single stage with Maven and JDK.
- Image B uses multi-stage: Maven build stage and a slim JRE runtime stage.
Which statement best describes their size difference?
Think about what is included in the final image layers.
Multi-stage builds copy only the final jar and runtime dependencies, excluding build tools and source code, making the image smaller.
Choose the false statement about multi-stage Docker builds in Spring Boot projects.
Consider what is included in the final runtime image.
The final image usually excludes source code to keep it small and secure; including full source is not required and is discouraged.