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.
More on Write-a-Dockerfile tasks
Write a production Dockerfile for a Node.js API using a multi-stage build.IntermediateWrite a Dockerfile for a Python Flask app that runs with gunicorn as a non-root user.BeginnerWrite a Dockerfile for a Go service that produces a tiny image (under 20 MB).IntermediateWrite a multi-stage Dockerfile for a Java Spring Boot app built with Maven.IntermediateWrite a Dockerfile for a static React site served by Nginx.BeginnerThis Dockerfile rebuilds dependencies on every code change. Fix it.Beginner