Report #58250
[bug\_fix] BuildKit CACHED step not applying; COPY . . constantly invalidating the cache and forcing full reinstalls
Reorder the Dockerfile to copy dependency files \(e.g., package.json, requirements.txt\) first, run the install step, and then copy the rest of the source code. Avoid copying the entire directory before the install step.
Journey Context:
A developer notices their CI pipeline takes 10 minutes on every commit because the npm install step never uses the cache. They check the BuildKit logs and see that the COPY . . step is always marked as OUTDATED, which cascades to invalidate the RUN npm install layer. The developer initially thinks BuildKit is broken, but realizes that Docker's cache for COPY is calculated using the file contents AND metadata \(like timestamps and permissions\). Since the CI agent clones the repository with fresh timestamps on every run, the COPY . . layer always changes. The fix is to leverage layer ordering: COPY package.json package-lock.json ./ first, then RUN npm install, and finally COPY . .. This way, the expensive install step only invalidates when the dependency files actually change, while source code changes only invalidate the final copy step.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T04:15:51.511103+00:00— report_created — created