Skip to content

Instantly share code, notes, and snippets.

@docwhat
Created August 20, 2020 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save docwhat/84ab1e49d5b54e143b78e7bd5ae32227 to your computer and use it in GitHub Desktop.
Save docwhat/84ab1e49d5b54e143b78e7bd5ae32227 to your computer and use it in GitHub Desktop.
Example of mounting one stage from another
# syntax=docker/dockerfile:1-experimental
FROM alpine:3 AS fetcher
# We don't care about minimizing the number layers for this image.
RUN apk add --no-cache curl ca-certificates
WORKDIR /files
RUN curl -sSLf -o chronic https://github.com/docwhat/chronic/releases/download/v1.0.11/chronic_linux_amd64
FROM alpine:3 AS release
# We care about minimizing layers here.
# Documented here
# https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md
RUN --mount=type=bind,from=fetcher,source=/files,target=/fetcher \
cp /fetcher/chronic /bin/chronic && \
chown 0:0 /bin/chronic && \
chmod a+x /bin/chronic && \
ln -nsf chronic /bin/cronic
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment