Docker and CI/CD · Junior · Question 18 of 75
Why copy package.json and the lockfile before the rest of the source code?
- ✓Correct answer: So the
npm cilayer is cached until dependencies change - 2So the final image doesn't contain the source code
- 3Because
npm cifails if other files are already present
Explanation
A layer is rebuilt when its inputs change, and so is everything after it. Copying manifests first means editing code doesn't trigger a full reinstall.