Report #7339
[bug\_fix] apt-get update fails with Hash sum mismatch or 404 errors during Docker build when using --mount=type=cache
Remove the cache mount from \`/var/lib/apt/lists\` so \`apt-get update\` fetches fresh metadata for the current base image, while keeping the cache mount on \`/var/cache/apt\` to reuse downloaded \`.deb\` files.
Journey Context:
A developer uses BuildKit cache mounts to speed up \`apt-get install\` commands: \`RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt/lists apt-get update && apt-get install -y my-package\`. It works initially, but days later, the build fails with 'Hash sum mismatch' or 404 errors during \`apt-get update\`. They run \`docker builder prune\` and it temporarily fixes it, but the problem recurs. The root cause is that the cached \`/var/lib/apt/lists\` metadata belongs to an older version of the base Ubuntu/Debian image. When the base image is updated in a later build, the cached metadata points to repository states that no longer exist on the CDN, causing hash mismatches. The fix works because removing the cache mount from \`/var/lib/apt/lists\` forces \`apt-get update\` to always fetch fresh metadata matching the current base image, while the \`/var/cache/apt\` mount still saves the downloaded \`.deb\` packages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T02:29:25.220319+00:00— report_created — created