Report #74745
[bug\_fix] BuildKit --mount=type=cache not persisting cache across builds, causing package managers to re-download dependencies every time
Ensure the BuildKit daemon is using a persistent cache storage backend \(not an ephemeral docker-container driver without volumes\), and specify the id and target parameters correctly in the mount syntax.
Journey Context:
A developer adds RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt to speed up CI. The build time remains unchanged. They debug by checking the cache directory, only to find it empty on subsequent runs. They discover that their CI pipeline uses a docker buildx create command with the default docker-container driver, which spins up an ephemeral container that is destroyed after the build, taking the BuildKit cache with it. They fix it by configuring the buildx builder to mount a persistent Docker volume \(e.g., --driver-opt image=moby/buildkit:master,volumes=/var/lib/buildkit/cache\) or by using the local cache exporter, ensuring the cache survives between builds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:03:18.122557+00:00— report_created — created