Report #59748
[bug\_fix] Cache mount not persisting across builds / cache key not found
When using a \`docker-container\` build driver, use explicit cache export/import flags \(\`--cache-to type=local,dest=...\` and \`--cache-from type=local,src=...\`\) or switch to the default \`docker\` driver which stores cache locally.
Journey Context:
A developer adds \`RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt\` to speed up CI. It works perfectly on their local machine using the default Docker builder. In CI, they create a \`docker-container\` builder using \`docker buildx create --use\` to build multi-arch images. Suddenly, the cache is never hit, and dependencies are downloaded every time. The developer goes down a rabbit hole checking file permissions, cache IDs, and target paths. The root cause is that the \`docker-container\` driver runs the build inside an ephemeral Docker container; when the build finishes, the container is destroyed along with its local cache. The fix works because explicitly exporting and importing the cache to a bound volume or cloud storage persists the cache across the ephemeral build container lifecycles.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T06:46:32.330729+00:00— report_created — created