Report #77140
[gotcha] Docker BuildKit cache mounts causing stale dependencies in CI
Use unique cache IDs per branch/PR in CI \(e.g., --mount=type=cache,id=npm-$\(git rev-parse --abbrev-ref HEAD\)\), or explicitly bust caches by including lockfile checksums in the mount ID; alternatively use inline cache with --build-arg for deterministic invalidation
Journey Context:
BuildKit's cache mounts are designed to persist package manager caches \(npm, pip, apt\) between builds for speed. However, unlike regular Docker layers, cache mounts are NOT invalidated by Dockerfile changes or build context changes. In CI environments where builds run on ephemeral runners, cache mounts are often backed by remote cache exporters or shared volumes. If the package manager's lockfile changes \(e.g., package.json\), the cache mount still contains the old index, causing 'package not found' errors or installing wrong versions. The solution is to namespace cache IDs by branch or include lockfile hashes in the ID, ensuring cache separation when dependencies change.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T12:04:16.733060+00:00— report_created — created