Bird
0
0

Which is the correct way to specify a cache mount in a Dockerfile RUN instruction to cache dependencies?

easy📝 Syntax Q3 of 15
Docker - Image Optimization
Which is the correct way to specify a cache mount in a Dockerfile RUN instruction to cache dependencies?
ARUN --mount=type=cache,target=/root/.cache npm install
BRUN --cache=type=mount,target=/root/.cache npm install
CRUN --mount=cache,target=/root/.cache npm install
DRUN --mount=type=volume,target=/root/.cache npm install
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct syntax

    The correct syntax for cache mounts in Dockerfile RUN commands uses --mount=type=cache.
  2. Step 2: Analyze options

    RUN --mount=type=cache,target=/root/.cache npm install correctly uses --mount=type=cache,target=.... RUN --cache=type=mount,target=/root/.cache npm install uses an invalid flag --cache=. RUN --mount=cache,target=/root/.cache npm install misses type= keyword. RUN --mount=type=volume,target=/root/.cache npm install uses type=volume which is not for build cache.
  3. Final Answer:

    RUN --mount=type=cache,target=/root/.cache npm install -> Option A
  4. Quick Check:

    Correct syntax includes type=cache [OK]
Quick Trick: Use --mount=type=cache,target=path for cache mounts [OK]
Common Mistakes:
  • Omitting 'type=cache' in the mount option
  • Using --cache instead of --mount
  • Confusing cache mounts with volume mounts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Docker Quizzes