Created
January 16, 2018 11:16
-
-
Save sdenier/dca839a7d71706f60d215de17bb276e4 to your computer and use it in GitHub Desktop.
Parameterize a multi-stage Docker build output using ARG and ENV
This file contains hidden or 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 MODULE=my_app -t my_app . |
This file contains hidden or 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
# Build the $MODULE target (which produces a $MODULE binary) | |
FROM debian:latest as builder | |
ARG MODULE | |
COPY src/ . | |
RUN make ${MODULE} | |
# Build a minimal image containing the $MODULE binary | |
FROM alpine:latest as product | |
## important! declare MODULE for each stage where you need to use it | |
ARG MODULE | |
COPY --from=builder /${MODULE} / | |
# Define an environnement variable $CALL_MODULE in the image | |
ENV CALL_MODULE=${MODULE} | |
# Docker does not substitute variable in ENTRYPOINT instruction | |
# So we define an environnement variable inside the image which will be the ENTRYPOINT | |
ENTRYPOINT /${CALL_MODULE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment