Call out FROM can take a previous stage (#9566)

The included example could be improved with a more concrete use case, but illustrates the capability as is.
This commit is contained in:
Jeff Anderson 2019-12-09 05:48:45 -05:00 committed by Usha Mandya
parent 06c7f18df8
commit eeea0d586a
1 changed files with 16 additions and 0 deletions

View File

@ -181,3 +181,19 @@ if necessary and copies the artifact from there. The syntax is:
COPY --from=nginx:latest /etc/nginx/nginx.conf /nginx.conf COPY --from=nginx:latest /etc/nginx/nginx.conf /nginx.conf
``` ```
## Use a previous stage as a new stage
You can pick up where a previous stage left off by referring to it when using the `FROM` directive. For example:
```Dockerfile
FROM alpine:latest as builder
RUN apk --no-cache add build-base
FROM builder as build1
COPY source1.cpp source.cpp
RUN g++ -o /binary source.cpp
FROM builder as build2
COPY source2.cpp source.cpp
RUN g++ -o /binary source.cpp
```