Report #79718
[gotcha] Docker BuildKit cache mounts retain stale data across builds causing dependency version conflicts
Include a cache-busting identifier in the cache mount ID that changes when dependencies change \(e.g., \`--mount=type=cache,id=apt-$\(checksum package.json\),target=/var/cache/apt\`\), or avoid cache mounts entirely for language package managers \(pip, npm\) where strict reproducibility is required, relying on layer caching instead.
Journey Context:
Developers use \`RUN --mount=type=cache,target=/root/.cache/pip\` to speed up Docker builds by reusing downloaded packages between builds. However, when they update requirements.txt, the cache mount persists the old .whl files from previous builds because BuildKit cache mounts are keyed only by the ID and target path, not by the build context. This results in images containing a mix of old and new package versions or build failures when the cache contains incompatible transitive dependencies. The \`docker build --no-cache\` flag does not invalidate these mounts, requiring manual \`docker builder prune\` or cache ID versioning.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T16:24:33.024200+00:00— report_created — created