Cloud & DevOps · Question 14 · Hard

Cloud & DevOps question 14

In a Dockerfile for a Node.js app, why are package.json and package-lock.json usually copied, and dependencies installed, BEFORE the rest of the source code is copied?

  1. Docker requires dependency files to be copied first
  2. It makes the final image run faster at runtime
  3. It prevents the source code from being included in the image
  4. The dependency-install layer stays cached and is reused when only the source code changes, which speeds up rebuilds
Answer and explanation

Answer: D. The dependency-install layer stays cached and is reused when only the source code changes, which speeds up rebuilds

Explanation: Docker caches each instruction's layer and rebuilds from the first changed layer onward. If the dependency manifests are unchanged, the slow install step is reused from cache.

Previous: The file server.log contains these four lines: ERROR disk full INFO ok ERROR… · Next: Under the shared responsibility model for IaaS, who is responsible for…

Practise cloud & devops

Try a fresh set of cloud & devops questions with an explanation after every answer, free and without signing up: Cloud & DevOps practice. Or sit a full placement mock test.

More cloud & devops questions

More technical & programming practice

GenAI Basics · Pseudo-code · C Programming · Java · Python · Data Structures · Algorithms · Object-Oriented Programming

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge