Report #45193
[bug\_fix] Files created during RUN --mount=type=bind disappear in the final Docker image
Use \`COPY\` instead of \`--mount=type=bind\` if the files need to persist in the image, or explicitly \`COPY\` them out, as bind mounts are strictly ephemeral during the build step and do not modify the image layers.
Journey Context:
A developer tries to use BuildKit's \`RUN --mount=type=bind,from=builder,/src,/src\` to access source code from another stage. The build compiles successfully, but when the final image runs, the compiled binaries are missing. They go down a rabbit hole checking file permissions and mount paths. The realization is that \`--mount=type=bind\` \(like all \`RUN\` mounts\) is strictly temporary for the duration of that \`RUN\` step. Any files generated inside the mount point disappear with the mount. To persist files, they must either be written to a directory outside the mount point during the \`RUN\` step, or the developer must use the standard \`COPY --from=builder\` instruction, which is the correct mechanism for persisting files across stages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T06:19:31.271563+00:00— report_created — created