mirror of
https://github.com/docker/docs.git
synced 2026-03-27 14:28:47 +07:00
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
This commit is contained in:
11
content/manuals/build/cache/optimize.md
vendored
11
content/manuals/build/cache/optimize.md
vendored
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user