Docker and CI/CD · Middle · Question 2 of 75
Why does this Dockerfile reinstall all dependencies on every code change?
``dockerfile
COPY . .
RUN npm ci
- ✓Correct answer: Any file change invalidates
COPY . ., sonpm cireruns too - 2
npm cialways ignores the Docker build cache by design - 3
COPY . .must come afterRUN, or the build fails
Explanation
Cache invalidation cascades: once a layer changes, every later layer is rebuilt. Copy package.json and the lockfile, run npm ci, then copy the rest.