Bird
0
0

When creating a multi-stage Dockerfile for a Java application using distroless images, which strategy best minimizes image size and enhances security?

hard📝 Workflow Q8 of 15
Docker - Image Optimization
When creating a multi-stage Dockerfile for a Java application using distroless images, which strategy best minimizes image size and enhances security?
AUse a distroless image as the build stage and copy source code directly into it
BBuild the app in a full JDK image, then copy only the compiled JAR into a distroless base image
CBuild and run the app entirely within a distroless image without multi-stage builds
DUse a full OS base image for both build and runtime stages to simplify debugging
Step-by-Step Solution
Solution:
  1. Step 1: Understand multi-stage builds

    Multi-stage builds allow compiling in a full environment and copying only necessary artifacts to a minimal runtime image.
  2. Step 2: Apply to distroless images

    Building in a full JDK image then copying the JAR to a distroless base image reduces size and attack surface.
  3. Final Answer:

    Build the app in a full JDK image, then copy only the compiled JAR into a distroless base image -> Option B
  4. Quick Check:

    Build fully, run minimal distroless image [OK]
Quick Trick: Build in full image, run in distroless for minimal size [OK]
Common Mistakes:
  • Trying to build directly inside distroless images
  • Copying source code instead of compiled artifacts
  • Using full OS images for runtime unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes