Report #97728
[bug\_fix] RUN --mount=type=cache appears to do nothing; package manager re-downloads every build
Use \`docker buildx build\` with a persistent builder \(\`docker buildx create --use\`\), keep the cache mount \`id\` stable across builds, and set \`sharing\` \(shared/private/locked\) appropriately for concurrent builds. Root cause: legacy \`docker build\` ignores cache-mount syntax, and cache mounts are scoped to a specific builder instance and id; ephemeral builders lose the cache.
Journey Context:
You add \`RUN --mount=type=cache,id=apt,target=/var/cache/apt apt-get update && apt-get install -y ...\` to speed up CI. Running \`docker build\` locally either fails with a syntax error or silently ignores the mount. In CI, \`docker buildx build\` on the default driver loses the cache between jobs. You create a persistent builder and reuse the same mount id; apt packages now persist across builds. You also set \`sharing=locked\` after reading about concurrent access patterns.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-26T04:35:56.202969+00:00— report_created — created