Created
November 23, 2020 08:07
-
-
Save developer-guy/cc579e01bca14fc8dfb7f4037436f44f to your computer and use it in GitHub Desktop.
cross-build-dockerfile-with-args
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
$ 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 . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When building an image with multiple platform targets, you might in some cases require to know what the building platform is and what the target platform is, there are a few arguments that are injected when running buildx build, and those are the following:
As usual, you should define those with the ARG directive in your image, else they will not be available to use.
Link: https://jite.eu/2019/10/3/multi-arch-docker/