Bird
0
0

You want to optimize your Spring Boot Dockerfile to reduce image size and build time. Which multi-stage build strategy helps achieve this?

hard📝 Conceptual Q8 of 15
Spring Boot - Docker and Deployment
You want to optimize your Spring Boot Dockerfile to reduce image size and build time. Which multi-stage build strategy helps achieve this?
AUse a build stage that includes the full source code in the final image
BUse a single stage with Maven and OpenJDK to avoid copying files
CUse multiple runtime stages with different JDK versions
DUse a Maven build stage to compile, then copy only the jar to a minimal OpenJDK runtime stage
Step-by-Step Solution
Solution:
  1. Step 1: Identify optimization goals

    Reducing image size and build time means excluding unnecessary build tools from final image.
  2. Step 2: Choose strategy matching goals

    Using Maven to build and copying only the jar to a minimal runtime image achieves this.
  3. Final Answer:

    Use a Maven build stage to compile, then copy only the jar to a minimal OpenJDK runtime stage -> Option D
  4. Quick Check:

    Build stage + minimal runtime = optimized image [OK]
Quick Trick: Build with Maven, run with minimal JDK for best results [OK]
Common Mistakes:
  • Using single stage with all tools increases image size
  • Using multiple runtime stages wastes resources
  • Including full source in final image bloats size

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes