How should I build my images for both arm64 and amd64 so I can move onto Graviton?
Question
I want to cut costs on AWS by moving my EC2 fleet to Graviton (arm64) instances; the price/performance gain looks significant. The problem: my CI pipeline (GitHub Actions) currently only produces amd64 images. I have a Go service and a Laravel API, both running as containers. I want the same image to run cleanly on both the old amd64 nodes and the new arm64 ones. How do I build the images correctly for both architectures, and what pitfalls should I watch for?
Answer
Short answer
Use docker buildx to produce a manifest list that bundles both architectures under a single tag; Docker pulls the right variant for the node it lands on.
Context
The Go side is nearly free; on the interpreted side the real decision is QEMU versus native runners.
Why
- The core tool is buildx and a multi-arch manifest. A single
docker buildx build --pushwith--platform linux/amd64,linux/arm64creates two images plus a manifest list. The tagmyimage:1.4points at both; a Graviton node pullsarm64, an old node pullsamd64, and you never seeexec format error.
What to do
-
For Go, cross-compilation is effectively free. Switching architecture in Go is a
GOARCHmatter — no emulation needed. Use theTARGETARCHarg buildx injects and keep the build on an amd64 runner:FROM --platform=$BUILDPLATFORM golang:1.24 AS build ARG TARGETOS TARGETARCH WORKDIR /src COPY . . RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /app ./cmd/api FROM gcr.io/distroless/static COPY --from=build /app /app ENTRYPOINT ["/app"] -
For an interpreted app (Laravel) there are two paths. The official PHP images are already multi-arch, so it works; but building the arm64 layer on an amd64 runner via QEMU emulation gets noticeably slow if you compile extensions (
pecl,docker-php-ext-install). The alternative: build each architecture on its own native runner, then merge withdocker buildx imagetools create. GitHub now offers arm64 runners; if build time hurts, a matrix on native runners is far faster and more reliable. -
Make sure your dependencies have arm64 builds. The base image, any third-party binaries, extensions like
mysqli/gd, even the natively compiled parts of some Composer/npm packages must exist for arm64. It’s usually fine, but a single missing binary sinks the whole image. -
Test on real arm64 before going to prod. “It built” under emulation is not “it runs”. Spin up one arm64 node and smoke-test it; float behaviour, time zones and native-library differences bite rarely but they do.
Bottom line: personally I’d build the Go service multi-arch in one pipeline with TARGETARCH buildx — cheap, clean, no extra runners. On the Laravel side, if extension compilation bloats the build, I’d set up a matrix with native arm64 runners and merge via imagetools create rather than lean on QEMU. And I wouldn’t flip the fleet overnight: make the images multi-arch first, run a mixed fleet, and only shift weight to Graviton once arm64 is verified.
Compiled from questions I have run into in the field or been asked.
Comments
Sign in with your GitHub account to join the discussion. Comments are stored in GitHub Discussions.