Report #101007
[bug\_fix] BuildKit cache mount does not persist package-manager data and builds still re-download everything
Add \`\# syntax=docker/dockerfile:1\` at the top; mount the exact directory each tool uses \(e.g. \`/root/.npm\`, \`/go/pkg/mod\`, \`/root/.cache/go-build\`, \`/var/cache/apt\` and \`/var/lib/apt\`\); for apt remove \`/etc/apt/apt.conf.d/docker-clean\` and avoid \`rm -rf /var/lib/apt/lists/\*\`; use \`sharing=locked\` for apt to prevent concurrent corruption.
Journey Context:
A developer adds \`RUN --mount=type=cache,target=/var/cache/apt apt-get update && apt-get install -y build-essential\` expecting apt packages to be cached across builds, but each rebuild still downloads all \`.deb\` files. After reading the cache-mount docs they realize Debian's \`docker-clean\` hook wipes \`/var/cache/apt/archives\` at the end of apt-get install, and apt also stores state in \`/var/lib/apt\`. They remove the hook, mount both directories with \`sharing=locked\`, and stop deleting the lists. Now apt reuses downloaded packages. The root cause is that a cache mount must cover the tool's actual cache paths and must survive any cleanup the tool performs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-06T04:49:40.395382+00:00— report_created — created