Report #71188
[bug\_fix] BuildKit RUN --mount=type=cache does not persist cache across CI runs, causing full rebuilds every time.
Use \`docker buildx build\` with \`--cache-to\` and \`--cache-from\` pointing to a remote registry or local directory export, or ensure the buildx builder container is not destroyed between CI runs.
Journey Context:
A developer adds \`RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt\` to speed up CI. Locally, it works perfectly; subsequent builds are instant. In GitHub Actions using \`docker buildx build\`, it re-downloads everything every time. They dive into BuildKit internals, checking cache scopes and IDs. They eventually discover that CI creates an ephemeral \`docker-container\` builder using \`docker buildx create --use\`, which is destroyed after the job finishes. The cache mount only lives inside that builder's container filesystem. The fix works because \`--cache-to=type=registry,ref=myimage:cache\` exports the cache manifest and layers to an external persistent store, and \`--cache-from\` imports them on the next run, bypassing the ephemeral builder's local storage limitation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:04:13.702975+00:00— report_created — created