Skip to content

Commit 15041eb

Browse files
authored
Merge pull request moby#5386 from dvdksn/onbuild-from-docs-followup
docs: remove `from` limitation for onbuild
2 parents 60e5345 + 016fa95 commit 15041eb

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

frontend/dockerfile/docs/reference.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,8 +2622,6 @@ another build. The trigger will be executed in the context of the
26222622
downstream build, as if it had been inserted immediately after the
26232623
`FROM` instruction in the downstream Dockerfile.
26242624

2625-
Any build instruction can be registered as a trigger.
2626-
26272625
This is useful if you are building an image which will be used as a base
26282626
to build other images, for example an application build environment or a
26292627
daemon which may be customized with user-specific configuration.
@@ -2666,11 +2664,26 @@ ONBUILD ADD . /app/src
26662664
ONBUILD RUN /usr/local/bin/python-build --dir /app/src
26672665
```
26682666

2667+
### Copy or mount from stage, image, or context
2668+
2669+
As of Dockerfile syntax 1.11, you can use `ONBUILD` with instructions that copy
2670+
or mount files from other stages, images, or build contexts. For example:
2671+
2672+
```dockerfile
2673+
# syntax=docker/dockerfile:1.11
2674+
FROM alpine AS baseimage
2675+
ONBUILD COPY --from=build /usr/bin/app /app
2676+
ONBUILD RUN --mount=from=config,target=/opt/appconfig ...
2677+
```
2678+
2679+
If the source of `from` is a build stage, the stage must be defined in the
2680+
Dockerfile where `ONBUILD` gets triggered. If it's a named context, that
2681+
context must be passed to the downstream build.
2682+
26692683
### ONBUILD limitations
26702684

26712685
- Chaining `ONBUILD` instructions using `ONBUILD ONBUILD` isn't allowed.
26722686
- The `ONBUILD` instruction may not trigger `FROM` or `MAINTAINER` instructions.
2673-
- `ONBUILD COPY --from` is [not supported](https://github.com/moby/buildkit/issues/816).
26742687

26752688
## STOPSIGNAL
26762689

0 commit comments

Comments
 (0)