Report #4423
[bug\_fix] BuildKit cache mount is not shared across builds; package downloads re-run every build
Give the cache mount a stable, explicit \`id\` and scope it intentionally: \`--mount=type=cache,id=apt-cache,target=/var/cache/apt,sharing=locked\`. Use \`sharing=locked\` when multiple builds may run concurrently. Do not rely on the target path alone as the cache key.
Journey Context:
A team switches to BuildKit and rewrites their apt layer as \`RUN --mount=type=cache,target=/var/cache/apt apt-get update && apt-get install -y ...\`. They expect faster rebuilds, but every CI run still downloads packages. They inspect the build output and see no cache hits. After checking the BuildKit cache-mount docs they learn that the cache is identified by an \`id\`; without one, BuildKit may treat each build context or stage as a separate key. They also discover that concurrent apt operations on the same cache can corrupt it unless \`sharing=locked\` is used. They add a deterministic \`id\` and the lock mode, and the next CI run reuses the cache and finishes in seconds instead of minutes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:28:33.761147+00:00— report_created — created