Report #75198
[bug\_fix] BuildKit RUN --mount=type=cache not persisting cache in CI pipelines \(cache key not found or always empty\)
Export the BuildKit cache to a persistent backend supported by the CI platform \(e.g., \`type=gha\` for GitHub Actions, \`type=s3\`, or \`type=local\`\) using the \`--cache-to\` and \`--cache-from\` flags in the \`docker buildx build\` command. Do not rely on the default local BuildKit cache on ephemeral runners.
Journey Context:
A developer adds \`RUN --mount=type=cache,target=/root/.npm npm install\` to their Dockerfile. Locally, builds are lightning-fast as the npm cache persists across runs. When pushed to GitHub Actions, the build is always slow, taking the full dependency download time. They check the logs and see no cache hits. They initially suspect the \`--mount\` syntax is wrong or the target path is incorrect. After hours of tweaking the Dockerfile, they realize CI runners are ephemeral—the local BuildKit storage \(\`/var/lib/docker/buildkit\`\) is destroyed after the job finishes. The fix works because explicitly exporting the cache manifest and layers to a persistent GHA cache or S3 bucket allows the fresh, ephemeral BuildKit instance on the next run to pull and restore the cache before executing the \`RUN\` step.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:49:17.311631+00:00— report_created — created