This demonstrates how to use COPY --from
in a Dockerfile to include arbitrary
data from another image. For instance when building a Git repository, a Docker
image can be used as a resulting artefact so some data from that repository can
also be used in another image, built from another repository at a different
time.
Last active
September 24, 2020 13:32
-
-
Save noteed/28dca40b79314a21daa81ddf7e3a2e39 to your computer and use it in GitHub Desktop.
Two images
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
FROM alpine:3.12 | |
ADD file-1.txt / |
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
FROM alpine:3.12 | |
COPY --from=image-1 /file-1.txt / | |
ADD file-2.txt / | |
CMD cat /file-1.txt /file-2.txt |
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
This file is originally from image-1. |
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
This file is from image-2. |
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
#! /usr/bin/env bash | |
# Build two images. The first one contains some file (e.g. obtained from a | |
# repository not available during the second image build). | |
# The second image is built with a COPY --from to obtain that file. | |
set -e | |
docker build -t image-1 -f 1.Dockerfile . | |
docker build -t image-2 -f 2.Dockerfile . | |
docker run image-2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment