Interview Prep/Docker/Dockerfile Instructions & Builds

Why do we copy `package.json` before the rest of the source?

BeginnerConceptDockerfile Instructions & Builds
Answer

To keep the dependency-install layer cacheable. Code changes often, dependencies rarely:

COPY package.json package-lock.json ./
RUN npm ci
COPY . .

Editing a source file only invalidates layers from COPY . . onward.

All Docker questions Roadmap: Docker & containers

More on Dockerfile Instructions & Builds