From eeea0d586af092ab24469330040f514fe5acd5b1 Mon Sep 17 00:00:00 2001 From: Jeff Anderson Date: Mon, 9 Dec 2019 05:48:45 -0500 Subject: [PATCH] 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. --- develop/develop-images/multistage-build.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/develop/develop-images/multistage-build.md b/develop/develop-images/multistage-build.md index 022a1741db..5eee89afab 100644 --- a/develop/develop-images/multistage-build.md +++ b/develop/develop-images/multistage-build.md @@ -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 ``` +## 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 +```