Report #1227
[bug\_fix] BuildKit cache mount directory is empty on subsequent builds; expected cached files are missing
Ensure the RUN --mount=type=cache,id=...,target=... uses the same id and target path across builds. Cache mounts are scoped by id and stage; a mismatched key presents a fresh empty directory instead of reusing populated cache data.
Journey Context:
We added RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt expecting faster rebuilds. On the next build, the layer re-downloaded everything. We inspected the mount and it was empty. After reading the BuildKit docs, we realized the previous successful build used a different target path in another Dockerfile. Because cache keys are derived from the mount id and target, the mismatch produced a fresh empty mount. Aligning id and target made the cache hit, and pip stopped re-downloading.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T19:53:24.957811+00:00— report_created — created