Intermediate Docker
Mike Metzger
Data Engineering Consultant
linux
windows
macos
x64_64
or amd64
arm64
arm7
os/cpu
, such as linux/amd64
--platform=$BUILDPLATFORM
flag$BUILDPLATFORM
represents the platform of the host running the buildARG
directiveTARGETOS
and TARGETARCH
ARG TARGETOS TARGETARCH
env
command.# Initial stage, using local platform FROM --platform=$BUILDPLATFORM golang:1.21 AS build
# Copy source into place WORKDIR /src COPY . .
# Pull the environment variables from the host ARG TARGETOS TARGETARCH
# Compile code using the ARG variables RUN env GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /final/app .
# Create container and load the cross-compiled code FROM alpine COPY --from=build /final/app /bin
docker build
, we must use docker buildx
with assorted optionsdocker buildx
provides more commands and capabilities over docker build
, including the option to specify a platformdocker buildx build --platform linux/amd64,linux/arm64 -t multi-platform-app .
docker buildx create --bootstrap --use
command.Intermediate Docker