Report #64476
[bug\_fix] RUN --mount=type=cache does not persist cache across different docker build runs in CI, resulting in full dependency downloads every time
Configure the CI runner to explicitly export and import the BuildKit cache using the \`--cache-to\` and \`--cache-from\` flags with a remote backend \(e.g., \`type=registry\` or \`type=gha\`\), rather than relying on the default local BuildKit cache storage.
Journey Context:
A developer adds \`RUN --mount=type=cache,target=/root/.cache/pip ...\` to their Dockerfile, expecting pip to reuse downloaded packages. It works perfectly on their local machine, but in GitHub Actions, the build times don't improve. They dig into BuildKit's architecture and realize that \`--mount=type=cache\` only persists data within the specific BuildKit daemon's storage directory. On their local machine, the daemon is persistent. In ephemeral CI environments, the BuildKit daemon is destroyed after the run, taking the local cache with it. The cache mount only helped within a single build \(e.g., across multi-stage builds in the same run\). To persist cache across isolated CI runs, they must configure BuildKit to push the cache manifest and data to an external storage backend using \`--cache-to=type=gha,mode=max\` and pull it using \`--cache-from=type=gha\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T14:42:42.109500+00:00— report_created — created