Report #98680
[bug\_fix] Every source-code edit reruns \`npm install\` even though package-lock.json did not change
Reorder Dockerfile so dependency manifests are copied and installed before the application source: \`COPY package\*.json ./\`, \`RUN npm ci\`, then \`COPY . .\`. Keep \`.dockerignore\` from excluding lockfiles and avoid copying build artifacts before the install layer.
Journey Context:
A developer writes a Node Dockerfile as \`FROM node:20\`, \`WORKDIR /app\`, \`COPY . .\`, \`RUN npm ci\`. Initially it builds fine, but every small code change triggers a full dependency reinstall. They inspect BuildKit output and see the \`RUN npm ci\` layer is never cached. The root cause is Docker's layer-cache rule: once a layer's inputs change, every subsequent layer is invalidated. \`COPY . .\` hashes the entire context, so any file edit changes that layer and forces the \`RUN npm ci\` below it to rerun. By copying only \`package\*.json\` first, the expensive \`npm ci\` layer depends only on the lockfile. Subsequent \`COPY . .\` for source files then only invalidates the build step. This is the canonical dependency-then-source ordering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-28T04:35:36.014822+00:00— report_created — created