Skip to content

Instantly share code, notes, and snippets.

@sdenier
Created January 16, 2018 11:16
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdenier/dca839a7d71706f60d215de17bb276e4 to your computer and use it in GitHub Desktop.
Save sdenier/dca839a7d71706f60d215de17bb276e4 to your computer and use it in GitHub Desktop.
Parameterize a multi-stage Docker build output using ARG and ENV
docker build --build-arg MODULE=my_app -t my_app .
# 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