# How should I build my images for both arm64 and amd64 so I can move onto Graviton?

> Bundle both architectures under one buildx tag, cross-compile Go with TARGETARCH, and use native arm64 runners when extension builds drag under QEMU.

- Asked: 2026-11-06
- Answered: 2026-11-10
- Tags: Docker, AWS
- Source: https://muhammetsafak.com/just-ask/build-images-both-arm64-amd64-move-onto-graviton/
- Language: en-US
- Author: Muhammet Şafak

---
**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?


## 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](https://muhammetsafak.com/just-ask/multi-platform-go-cli-distribution-with-goreleaser-and-homebrew/) is a `GOARCH` matter — no emulation needed. Use the `TARGETARCH` arg buildx injects and keep the build on an amd64 runner:

   ```dockerfile
   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.*

## Related Reading

- [My containers keep getting OOMKilled—how do I set memory limits correctly for PHP-FPM and Go?](https://muhammetsafak.com/just-ask/containers-oomkilled-set-memory-limits-php-fpm-go/) — Just Ask
- [My Go worker in a container never receives SIGTERM and won't shut down gracefully—is this a PID 1 problem?](https://muhammetsafak.com/just-ask/go-worker-never-receives-sigterm-pid-1-problem/) — Just Ask
- [My non-root container can't write to the mounted storage directory—how do I fix the permissions?](https://muhammetsafak.com/just-ask/my-non-root-container-cant-write-to-the-mounted-storage-directory/) — Just Ask
