Skip to content

Instantly share code, notes, and snippets.

@inductor
Last active December 13, 2021 03:29
Show Gist options
  • Save inductor/b79be2c3c53cadcc1755b34e9921833c to your computer and use it in GitHub Desktop.
Save inductor/b79be2c3c53cadcc1755b34e9921833c to your computer and use it in GitHub Desktop.
docker-multi-stage-build.sh
set -ex
cat <<EOF > Dockerfile
FROM debian:buster-slim as dependency
WORKDIR /app
COPY test.sh .
RUN ./test.sh
FROM debian:buster-slim as target-0
WORKDIR /app
COPY --from=dependency /app/* /app/
RUN echo 'target-0' > /app/env
CMD ["cat", "/app/env"]
FROM debian:buster-slim as target-1
WORKDIR /app
COPY --from=dependency /app/* /app/
RUN echo 'target-1' > /app/env
CMD ["cat", "/app/env"]
EOF
docker build -t test-0:latest --target target-0 .
docker build -t test-1:latest --target target-1 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment