0
0
Spring Bootframework~20 mins

Multi-stage Docker builds in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multi-stage Docker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the main benefit of using multi-stage Docker builds in Spring Boot applications?

Consider a Spring Boot app Dockerfile using multi-stage builds. What is the primary advantage of this approach?

AIt automatically scales the application based on CPU usage.
BIt allows running multiple containers from the same image simultaneously.
CIt reduces the final image size by separating build and runtime environments.
DIt enables hot-reloading of code changes inside the container.
Attempts:
2 left
💡 Hint

Think about what happens when you separate build tools from the runtime environment.

📝 Syntax
intermediate
2:00remaining
Which Dockerfile snippet correctly copies only the built Spring Boot jar to the final image?

Given a multi-stage Dockerfile, which COPY command correctly copies the built jar from the build stage named 'builder'?

ACOPY /app/target/myapp.jar /app/myapp.jar
BCOPY --from=builder /app/target/myapp.jar /app/myapp.jar
CCOPY --stage=builder /app/myapp.jar /app/myapp.jar
DCOPY --from=builder /myapp.jar /app/myapp.jar
Attempts:
2 left
💡 Hint

Remember the syntax for copying files from a named build stage.

🔧 Debug
advanced
2:30remaining
Why does this multi-stage Docker build fail to run the Spring Boot app?

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?

AThe base image openjdk:17-jdk-slim does not support running Java apps.
BThe ENTRYPOINT syntax is invalid and causes a syntax error.
CThe Maven build stage is missing the JDK, so the jar is not created.
DThe wildcard *.jar in COPY does not work; it needs the exact jar filename.
Attempts:
2 left
💡 Hint

Consider how Docker COPY handles wildcards.

state_output
advanced
2:00remaining
What is the size difference between single-stage and multi-stage Spring Boot Docker images?

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?

AImage B is significantly smaller because it excludes build tools and source files.
BImage A is smaller because it has everything in one layer.
CBoth images have the same size because the jar file is the same.
DImage B is larger because it has two stages increasing size.
Attempts:
2 left
💡 Hint

Think about what is included in the final image layers.

🧠 Conceptual
expert
3:00remaining
Which statement about multi-stage Docker builds for Spring Boot apps is FALSE?

Choose the false statement about multi-stage Docker builds in Spring Boot projects.

AMulti-stage builds require the final image to include the entire source code for debugging.
BMulti-stage builds can reduce attack surface by minimizing installed packages in the runtime.
CMulti-stage builds allow caching dependencies separately to speed up rebuilds.
DMulti-stage builds improve security by excluding build tools from the runtime image.
Attempts:
2 left
💡 Hint

Consider what is included in the final runtime image.