Interview Prep/Real-World Interview/Write-a-Dockerfile tasks

Write a Dockerfile that builds multi-architecture images (amd64 and arm64) and push them.

AdvancedHands-onWrite-a-Dockerfile tasks
Answer
# syntax=docker/dockerfile:1
FROM --platform=$BUILDPLATFORM golang:1.23 AS build
ARG TARGETOS TARGETARCH
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /out/app .

FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/app /app
ENTRYPOINT ["/app"]
docker buildx create --use --name multi
docker buildx build --platform linux/amd64,linux/arm64 -t myrepo/app:1.0.0 --push .

Key trick → --platform=$BUILDPLATFORM runs the compiler natively and cross-compiles with TARGETARCH. That is much faster than emulating arm64 through QEMU.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Dockerfile tasks