Skip to content

Instantly share code, notes, and snippets.

@Syerram
Last active February 20, 2020 06:09
Show Gist options
  • Save Syerram/9a2ec3dc8c79feadf27ed95950f0ba80 to your computer and use it in GitHub Desktop.
Save Syerram/9a2ec3dc8c79feadf27ed95950f0ba80 to your computer and use it in GitHub Desktop.
multi-stage-dockerfile
docker build --build-arg BASE_IMAGE_VERSION=1.31.1 \
--build-arg LABEL_1=1.11 \
--build-arg BASE_IMAGE=alpine:3.8.5 \
--build-arg LABEL_2=2.22 \
--build-arg LABEL_3=3.33
-t multi-stage-image:v1 .
# inspect the image and see the labels, notice it pulls alpine version 3.8.5
# accept base image versions or an entire base image for all stages
ARG BASE_IMAGE_VERSION
ARG BASE_IMAGE
FROM busybox:$BASE_IMAGE_VERSION as builder
ARG LABEL_1
COPY hello.txt hello.txt
RUN echo "in builder"
RUN echo $LABEL_1
LABEL org.opencontainers.image.revision=$LABEL_1
FROM $BASE_IMAGE
# Labels can be scoped to a stage
ARG LABEL_2
ARG LABEL_3
# copy the artifact from stage 1
COPY --from=builder hello.txt hello.txt
RUN cat hello.txt
RUN echo "in dev"
RUN echo $LABEL_3
LABEL org.opencontainers.image.source=$LABEL_2
LABEL org.opencontainers.image.vendor=$LABEL_3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment