Report #82599
[bug\_fix] BuildKit cache invalidates the COPY . . layer and all subsequent layers on every build, even if no source code changed.
Reorder the Dockerfile to copy dependency manifests \(e.g., package.json\) first, run the install step, and then COPY . . last. Add .git and other non-essential metadata-heavy directories to .dockerignore.
Journey Context:
A developer complains that their CI/CD pipeline takes 10 minutes on every commit because the Docker build cache is ignored. They verify that no application code changed, but the COPY . . layer always triggers a rebuild, invalidating the subsequent npm install. They dig into BuildKit cache mechanics, suspecting a bug. The root cause is that COPY computes its cache key using file metadata \(like last-modified timestamps\) in addition to content. If Git checks out files or a pre-commit hook touches a file, the timestamp changes, breaking the cache. By splitting the copy and adding .git to .dockerignore, the dependency installation layer remains cached until the manifest actually changes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T21:14:14.572691+00:00— report_created — created