Last active
February 20, 2020 06:09
-
-
Save Syerram/9a2ec3dc8c79feadf27ed95950f0ba80 to your computer and use it in GitHub Desktop.
multi-stage-dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ola! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment