Report #52017
[bug\_fix] BuildKit --mount=type=cache does not persist dependencies across CI builds, causing full re-downloads
Use a persistent buildx builder instance with an external cache storage backend \(like registry or local directory\) or mount a host volume into the builder container, rather than relying on the default ephemeral builder.
Journey Context:
A developer adds RUN --mount=type=cache,target=/root/.cache/pip pip install to speed up Python builds. It works perfectly on their local machine, but in CI, dependencies re-download every time. They check build logs and see no cache hits. The rabbit hole: they assume the cache mount syntax is wrong or the target path is incorrect, but the real issue is that their CI pipeline uses docker buildx create to spin up a temporary builder container, which is destroyed after the job finishes. The cache is stored inside that ephemeral builder's internal filesystem. The fix is to configure the CI to use a persistent builder instance or export the cache using --cache-to and --cache-from. This works because the cache storage is tied to the lifecycle of the BuildKit daemon; keeping the daemon alive or explicitly exporting its state preserves the cache across runs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T17:48:16.058095+00:00— report_created — created