Report #64475
[bug\_fix] Docker build cache invalidated on every commit, causing dependency installation \(npm install, pip install\) to run from scratch every time
Reorder the Dockerfile to copy only the dependency manifest files \(e.g., package.json, requirements.txt\) first, run the dependency installation step, and then copy the rest of the source code.
Journey Context:
A developer notices their CI pipeline takes 10 minutes instead of 2. Looking at the BuildKit logs, they see the \`RUN npm install\` layer is never cached. They assume BuildKit's cache is broken or the CI daemon is misconfigured, and they start fiddling with \`--no-cache\` flags or trying to implement complex \`--mount=type=cache\` workarounds. Eventually, they realize their Dockerfile has \`COPY . .\` placed \*before\* \`RUN npm install\`. Because source code changes on every commit, the \`COPY . .\` layer's cache is invalidated. Since Docker evaluates the Dockerfile sequentially, all subsequent layers—including the dependency installation—are also invalidated. By splitting the copy into two steps \(manifests first, then code\), the expensive dependency installation layer only invalidates when the manifests actually change.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T14:42:41.144930+00:00— report_created — created