I am successfully using Docker\'s Multi-Stage feature to build some code and then copy the resulting artifacts into a final image.
Is it possible to split this one big-i
If your Dockerfile currently looks something like:
FROM ubuntu:16.04 AS builder
RUN apt-get install build-essential
COPY . ./
RUN ./build_all_the_things \
&& make install PREFIX=/usr DESTDIR/out
FROM alpine:3.8
COPY --from=builder /out/ /
CMD the_app
You can readily split out the first part into its own Dockerfile, as is, and build it
docker build -f Dockerfile.builder -t me/builder .
COPY --from
has to name some previous stage in your Dockerfile, but the stage doesn’t need to do much; you can then change the second half of this to
FROM me/builder AS builder
FROM alpine:3.8
COPY --from=builder /out/ /
CMD the_app
The big downside of this is that you need two separate docker build
commands to actually build the final image. You could write a shell script to do both of them together.