How do you build for a different CPU architecture?
IntermediateConceptDockerfile Instructions & Builds
Answer
Use buildx with --platform. Foreign architectures run via QEMU user-mode emulation (slow) or native builder nodes; best is cross-compiling in the build stage using BUILDPLATFORM/TARGETARCH.
FROM --platform=$BUILDPLATFORM golang:1.23 AS build
ARG TARGETOS TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /app .
docker run --privileged --rm tonistiigi/binfmt --install all