Skip to content

Instantly share code, notes, and snippets.

@developer-guy
Created November 23, 2020 08:07
Show Gist options
  • Save developer-guy/cc579e01bca14fc8dfb7f4037436f44f to your computer and use it in GitHub Desktop.
Save developer-guy/cc579e01bca14fc8dfb7f4037436f44f to your computer and use it in GitHub Desktop.
cross-build-dockerfile-with-args
$ cat <<EOF >> Dockerfile
FROM alpine
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
ARG BUILDPLATFORM
ARG BUILDOS
ARG BUILDARCH
ARG BUILDVARIANT
RUN echo "Image target platform details :: "
RUN echo "TARGETPLATFORM : $TARGETPLATFORM"
RUN echo "TARGETOS : $TARGETOS"
RUN echo "TARGETARCH : $TARGETARCH"
RUN echo "TARGETVARIANT : $TARGETVARIANT"
RUN echo "Image build platform details :: "
RUN echo "BUILDPLATFORM : $BUILDPLATFORM"
RUN echo "BUILDOS : $BUILDOS"
RUN echo "BUILDARCH : $BUILDARCH"
RUN echo "BUILDVARIANT : $BUILDVARIANT"
EOF
$ docker buildx create --name my-new-builder --driver docker-container --use
$ docker buildx inspect --bootstrap
$ docker buildx build --platform=linux/amd64,linux/arm64,linux/s390x --push -t <dockerhub_id>/my-image:latest .
@developer-guy
Copy link
Author

Screen Shot 2020-11-23 at 11 12 14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment