Bird
0
0

You want to reduce Docker image size by copying only necessary files. Which Dockerfile snippet achieves this best?

hard📝 Application Q9 of 15
Remix - Deployment
You want to reduce Docker image size by copying only necessary files. Which Dockerfile snippet achieves this best?
ACOPY package.json package-lock.json ./ RUN npm install COPY . .
BCOPY . . RUN npm install
CRUN npm install COPY . .
DCOPY node_modules ./node_modules RUN npm install
Step-by-Step Solution
Solution:
  1. Step 1: Understand multi-stage copying

    Copying package files first and running npm install caches dependencies, reducing rebuild time.
  2. Step 2: Analyze options

    COPY package.json package-lock.json ./ RUN npm install COPY . . copies only package files first, installs, then copies rest; others copy all files upfront or copy node_modules incorrectly.
  3. Final Answer:

    Copy package files first, install, then copy rest. -> Option A
  4. Quick Check:

    Optimize image by layering COPY and RUN [OK]
Quick Trick: Copy package files first to cache npm install [OK]
Common Mistakes:
MISTAKES
  • Copying all files before npm install
  • Copying node_modules folder manually
  • Running npm install before copying files

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Remix Quizzes