Skip to content

Instantly share code, notes, and snippets.

@Syerram
Last active February 20, 2020 06:09
Show Gist options
  • Select an option

  • Save Syerram/9a2ec3dc8c79feadf27ed95950f0ba80 to your computer and use it in GitHub Desktop.

Select an option

Save Syerram/9a2ec3dc8c79feadf27ed95950f0ba80 to your computer and use it in GitHub Desktop.

Revisions

  1. Syerram revised this gist Feb 20, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,7 @@ 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"
  2. Syerram revised this gist Feb 20, 2020. 2 changed files with 11 additions and 11 deletions.
    14 changes: 6 additions & 8 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,15 @@
    # accept base image versions for all stage
    ARG BASE_IMAGE_VERSION_1
    ARG BASE_IMAGE_VERSION_2
    # this can be the whole base image
    # e.g. FROM $BASE_IMAGE:$BASE_IMAGE_VERSION
    FROM busybox:$BASE_IMAGE_VERSION_1 as builder
    # 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 alpine:$BASE_IMAGE_VERSION_2
    # Labels that are scope to a stage come after FROM
    FROM $BASE_IMAGE
    # Labels can be scoped to a stage
    ARG LABEL_2
    ARG LABEL_3
    COPY --from=builder hello.txt hello.txt
    8 changes: 5 additions & 3 deletions build-images.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    docker build --build-arg BASE_IMAGE_VERSION_1=1.31.1 \
    docker build --build-arg BASE_IMAGE_VERSION=1.31.1 \
    --build-arg LABEL_1=1.11 \
    --build-arg BASE_IMAGE_VERSION_2=3.8.5 \
    --build-arg BASE_IMAGE=alpine:3.8.5 \
    --build-arg LABEL_2=2.22 \
    --build-arg LABEL_3=3.33
    -t ms-test:v3 .
    -t multi-stage-image:v1 .

    # inspect the image and see the labels, notice it pulls alpine version 3.8.5
  3. Syerram revised this gist Feb 20, 2020. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    # accept base image versions for all stage
    ARG BASE_IMAGE_VERSION_1
    ARG BASE_IMAGE_VERSION_2
    # this can be the whole base image
    # e.g. FROM $BASE_IMAGE:$BASE_IMAGE_VERSION
    FROM busybox:$BASE_IMAGE_VERSION_1 as builder
    ARG LABEL_1
    COPY hello.txt hello.txt
    @@ -8,6 +11,7 @@ RUN echo $LABEL_1
    LABEL org.opencontainers.image.revision=$LABEL_1

    FROM alpine:$BASE_IMAGE_VERSION_2
    # Labels that are scope to a stage come after FROM
    ARG LABEL_2
    ARG LABEL_3
    COPY --from=builder hello.txt hello.txt
  4. Syerram revised this gist Feb 20, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions hello.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ola!
  5. Syerram revised this gist Feb 20, 2020. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion build-images.sh
    Original file line number Diff line number Diff line change
    @@ -1 +1,6 @@
    docker build --build-arg BASE_IMAGE_VERSION_1=1.31.1 --build-arg LABEL_1=1.11 --build-arg BASE_IMAGE_VERSION_2=3.8.5 --build-arg LABEL_2=2.22 --build-arg LABEL_3=3.33 -t ms-test:v3 .
    docker build --build-arg BASE_IMAGE_VERSION_1=1.31.1 \
    --build-arg LABEL_1=1.11 \
    --build-arg BASE_IMAGE_VERSION_2=3.8.5 \
    --build-arg LABEL_2=2.22 \
    --build-arg LABEL_3=3.33
    -t ms-test:v3 .
  6. Syerram created this gist Feb 20, 2020.
    18 changes: 18 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    ARG BASE_IMAGE_VERSION_1
    ARG BASE_IMAGE_VERSION_2
    FROM busybox:$BASE_IMAGE_VERSION_1 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 alpine:$BASE_IMAGE_VERSION_2
    ARG LABEL_2
    ARG LABEL_3
    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
    1 change: 1 addition & 0 deletions build-images.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    docker build --build-arg BASE_IMAGE_VERSION_1=1.31.1 --build-arg LABEL_1=1.11 --build-arg BASE_IMAGE_VERSION_2=3.8.5 --build-arg LABEL_2=2.22 --build-arg LABEL_3=3.33 -t ms-test:v3 .