From 7e01972e1ff874a9e01de476fb660dda650a6393 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Tue, 10 Feb 2026 17:43:46 +0100 Subject: [PATCH] fix: correct bind mount example with conflicting WORKDIR Changed WORKDIR from /app to /build so the build output path (/app/hello) does not overlap with the read-only bind mount target. Added clarification about writing output outside the mount point. Fixes #22637 --- content/manuals/build/cache/optimize.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/content/manuals/build/cache/optimize.md b/content/manuals/build/cache/optimize.md index e0350712bc6b..7f9fe9c0aba7 100644 --- a/content/manuals/build/cache/optimize.md +++ b/content/manuals/build/cache/optimize.md @@ -116,13 +116,16 @@ instruction in your Dockerfile: ```dockerfile FROM golang:latest -WORKDIR /app +WORKDIR /build RUN --mount=type=bind,target=. go build -o /app/hello ``` -In this example, the current directory is mounted into the build container -before the `go build` command gets executed. The source code is available in -the build container for the duration of that `RUN` instruction. When the +In this example, the current directory is mounted into the build container at +`/build` before the `go build` command gets executed. The build output is +written to `/app/hello`, which is outside the mount point. This distinction is +important: the build output must be written outside the bind mount target, +since the mount is read-only by default. The source code is available in the +build container for the duration of that `RUN` instruction. When the instruction is done executing, the mounted files are not persisted in the final image, or in the build cache. Only the output of the `go build` command remains.