Report #35445
[bug\_fix] BuildKit cache mount empty on subsequent builds \(dependencies re-downloaded\)
If using docker buildx with the docker-container driver, configure the driver to persist cache on the host using --driver-opt cache-to=/path/on/host. Also, ensure the cache target path exactly matches the package manager's internal cache directory \(e.g., /root/.cache/pip instead of /root/.cache\).
Journey Context:
A developer adds RUN --mount=type=cache,target=/root/.cache to a pip install step, expecting blazing fast rebuilds. Rebuilds are still slow, with pip downloading everything. They check logs and see pip uses /root/.cache/pip specifically, so they fix the target path. Still slow. The rabbit hole: they are using docker buildx create --use, which spawned a buildx\_buildkit\_default container. When the build finishes, the cache is trapped inside that ephemeral container. The fix works because mapping the BuildKit state directory to the host via --driver-opt ensures the cache mount state survives between docker buildx invocations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T13:58:00.170251+00:00— report_created — created