Report #92730
[bug\_fix] Docker build cache invalidated on every run, causing dependency installation \(e.g., npm install, pip install\) to re-run from scratch every time.
Reorder the Dockerfile to copy dependency manifests \(e.g., package.json, requirements.txt\) first, run the install command, and then copy the rest of the source code \(\`COPY . .\`\).
Journey Context:
A developer complains that their Docker builds take 10 minutes even when only changing a single line of source code. They check the build logs and notice \`npm install\` runs completely from scratch on every build. They initially suspect BuildKit cache is corrupted and try \`docker builder prune\`, but it doesn't help. They look closer at the Dockerfile and see \`COPY . .\` immediately followed by \`RUN npm install\`. Because any change to any file in the source code changes the layer hash of the \`COPY . .\` step, the cache for the subsequent \`RUN npm install\` layer is invalidated. By splitting the copy into two steps—first copying only \`package.json\` and \`package-lock.json\`, running \`npm install\`, and then copying the remaining source—the expensive install step is only re-run when the dependency manifests change.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T14:14:12.146111+00:00— report_created — created