Skip to content

Commit 16e5f28

Browse files
authored
Merge pull request #24125 from lacatoire/fix/issue-22637-bind-mount-example
fix: correct bind mount example with conflicting WORKDIR
2 parents 79d63b2 + 7e01972 commit 16e5f28

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

content/manuals/build/cache/optimize.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,16 @@ instruction in your Dockerfile:
116116

117117
```dockerfile
118118
FROM golang:latest
119-
WORKDIR /app
119+
WORKDIR /build
120120
RUN --mount=type=bind,target=. go build -o /app/hello
121121
```
122122

123-
In this example, the current directory is mounted into the build container
124-
before the `go build` command gets executed. The source code is available in
125-
the build container for the duration of that `RUN` instruction. When the
123+
In this example, the current directory is mounted into the build container at
124+
`/build` before the `go build` command gets executed. The build output is
125+
written to `/app/hello`, which is outside the mount point. This distinction is
126+
important: the build output must be written outside the bind mount target,
127+
since the mount is read-only by default. The source code is available in the
128+
build container for the duration of that `RUN` instruction. When the
126129
instruction is done executing, the mounted files are not persisted in the final
127130
image, or in the build cache. Only the output of the `go build` command
128131
remains.

0 commit comments

Comments
 (0)