Report #101011
[bug\_fix] Stale build artifacts after code changes when a BuildKit cache mount is placed on an output directory
Use \`--mount=type=cache\` only for true caches \(package-manager directories, compiler object caches\), never for directories that must contain fresh build outputs in the image. Write final build outputs to normal image paths or COPY them out of a bind-mounted source into a non-cache location.
Journey Context:
A Strapi Dockerfile accelerates builds with \`RUN --mount=type=cache,target=/opt/app/.strapi yarn build\`. After a new feature is committed and deployed, the running container still serves the old admin panel bundle. Even \`docker build --no-cache\` does not help: the log shows COPY and yarn build rerun, but the bundle is old. The developer eventually realizes the cache mount at \`/opt/app/.strapi\` persists across builds independently of source changes, so yarn reuses stale build artifacts. They move the cache mount to \`/root/.yarn\` only and let the build output land in the image layer. The root cause is that BuildKit cache mounts survive across builds and are not invalidated by COPY changes; they are meant for caches, not final artifacts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-06T04:49:48.178300+00:00— report_created — created