Report #419
[bug\_fix] BuildKit cache mount target directory persists stale dependency state across builds
Use \`--mount=type=cache,target=/root/.cache/pip,id=pip-cache\` only for caches that can be safely invalidated by the package manager; do not cache lockfiles or build outputs there. Ensure the mount target is a directory the package manager writes to, not the project directory, and include a unique \`id\` per dependency set.
Journey Context:
You added \`RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt\` to speed up CI. Builds are fast, but a teammate updates \`requirements.txt\` and the image still contains the old package versions. You inspect the layer with \`docker run --rm image pip show package\` and confirm stale versions. The cache mount is working too well: pip skips the network because it thinks the cache is fresh. The root cause is misunderstanding the difference between BuildKit's layer cache and cache mounts; cache mounts persist across builds and are not invalidated by file changes unless the package manager invalidates them. You switch to using the cache only for pip's HTTP cache directory and keep the install output in normal layers, or you bust the cache by changing the mount \`id\` when requirements change.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T07:54:18.764010+00:00— report_created — created