Report #36746
[bug\_fix] Docker layer cache is invalidated on every build even when dependencies haven't changed
Reorder Dockerfile instructions: copy dependency manifests \(e.g., \`package.json\`, \`requirements.txt\`\) first, run the dependency installation, and then copy the rest of the source code.
Journey Context:
A developer notices their CI pipeline takes 10 minutes on every commit because \`npm install\` always runs from scratch. They inspect the Dockerfile and see \`COPY . .\` followed by \`RUN npm install\`. BuildKit computes the cache hash based on the checksum of the copied context. Since source code changes every commit, the \`COPY . .\` layer hash changes, which invalidates the cache for all subsequent layers, including \`npm install\`. The fix is to separate the dependency copy from the source code copy. By copying only \`package.json\` first, the \`npm install\` layer is cached and only rebuilt when the package manifest changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T16:09:26.689587+00:00— report_created — created