Skip to content
Muhammet Şafak
tr
Answered:

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

  1. The core tool is buildx and a multi-arch manifest. A single docker buildx build --push with --platform linux/amd64,linux/arm64 creates two images plus a manifest list. The tag myimage:1.4 points at both; a Graviton node pulls arm64, an old node pulls amd64, and you never see exec format error.

What to do

  1. For Go, cross-compilation is effectively free. Switching architecture in Go is a GOARCH matter — no emulation needed. Use the TARGETARCH arg 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"]
  2. 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 with docker buildx imagetools create. GitHub now offers arm64 runners; if build time hurts, a matrix on native runners is far faster and more reliable.

  3. 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.

  4. 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.

More Questions

All questions

Search the site

Start typing to search posts, projects and pages.

Esc to close Powered by Pagefind