Bird
0
0

In a multi-stage Docker build, how can cache mounts be effectively used to speed up dependency installation?

hard📝 Workflow Q9 of 15
Docker - Image Optimization
In a multi-stage Docker build, how can cache mounts be effectively used to speed up dependency installation?
ADeclare cache mounts only in the final stage to reuse dependencies
BUse cache mounts in the build stage where dependencies are installed, then copy artifacts to later stages
CUse volumes instead of cache mounts for sharing dependencies between stages
DAvoid cache mounts and rely solely on Docker layer caching between stages
Step-by-Step Solution
Solution:
  1. Step 1: Understand multi-stage builds

    Multi-stage builds separate build steps into stages to optimize image size and caching.
  2. Step 2: Use cache mounts in build stages

    Cache mounts should be used in the stage where dependencies are installed to speed up repeated installs.
  3. Step 3: Copy artifacts forward

    After installing dependencies with cache mounts, copy the results to subsequent stages.
  4. Final Answer:

    Use cache mounts in the build stage where dependencies are installed, then copy artifacts to later stages -> Option B
  5. Quick Check:

    Cache mounts optimize build stages, not final stages [OK]
Quick Trick: Apply cache mounts in build stages, then copy outputs [OK]
Common Mistakes:
  • Using cache mounts only in final stages
  • Confusing volumes with cache mounts for build caching
  • Ignoring Docker layer caching benefits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes