Bird
0
0

You want to reduce your Docker image size by squashing layers but also keep some intermediate layers for caching. Which approach is best?

hard📝 Best Practice Q15 of 15
Docker - Image Optimization
You want to reduce your Docker image size by squashing layers but also keep some intermediate layers for caching. Which approach is best?
AUse multi-stage builds and squash only the final stage
BUse --squash on every build to squash all layers
CAvoid squashing and rely on layer caching only
DManually delete intermediate files after build
Step-by-Step Solution
Solution:
  1. Step 1: Understand multi-stage builds

    Multi-stage builds allow creating intermediate images for caching and a final optimized image.
  2. Step 2: Combine multi-stage builds with squashing

    Squashing only the final stage reduces image size while keeping intermediate layers for cache.
  3. Final Answer:

    Use multi-stage builds and squash only the final stage -> Option A
  4. Quick Check:

    Multi-stage + squash final stage = best size and cache [OK]
Quick Trick: Squash final stage in multi-stage builds for best results [OK]
Common Mistakes:
  • Squashing all layers loses caching benefits
  • Avoiding squashing misses size reduction
  • Deleting files manually is error-prone

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes