DevOps & CI/CD Bug Report

Multi-arch Docker build takes 50 minutes under QEMU and segfaults

Our linux/amd64,linux/arm64 image build went from 6 to 50 minutes and randomly died with a QEMU segmentation fault in npm install. Emulation was running the whole arm64 build. We split the build across native amd64 and arm64 runners, pushed by digest and merged the manifest list.

Ingrid Solberg Ingrid Solberg @ingridsolberg · November 30, 2026 · 8 min read · 109 Views
642-multi-arch-build-qemu-slow-native-arm64-runners

We started shipping our API image for both linux/amd64 and linux/arm64 so the platform team could move node pools to cheaper Arm instances. The basic exec format error problem was already solved (post 35 covers building with --platform). What we did not expect was the build itself: the CI job went from 6 minutes to between 45 and 55 minutes, and roughly one run in five failed in the arm64 leg:

#14 [linux/arm64 builder 4/7] RUN npm ci --omit=dev
#14 312.4 npm error code ELIFECYCLE
#14 318.9 qemu: uncaught target signal 11 (Segmentation fault) - core dumped
#14 ERROR: process "/bin/sh -c npm ci --omit=dev" did not complete successfully: exit code: 139

The amd64 leg of the same build finished in under five minutes every time.

Reproducing it

On any x86 runner with QEMU registered through binfmt_misc:

docker run --privileged --rm tonistiigi/binfmt --install arm64
docker buildx create --use --driver docker-container
time docker buildx build --platform linux/amd64,linux/arm64 -t example/api:test .

Timing on a 4 vCPU runner: amd64 stage 4 min 30 s, arm64 stage 41 min. The segfault appeared intermittently in steps that compiled native modules (bcrypt, sharp) or ran heavy Node processes.

What we ruled out

  • Slow network. Pulling base images and packages took the same time for both legs; the difference was CPU time in RUN steps.

  • Out of memory. Runner memory peaked under 60%, and the kernel log had no OOM kills.

  • A bad dependency version. The same lock file installed fine on an Apple Silicon laptop and on a real Graviton instance.

Root cause

Every arm64 RUN step executed under QEMU user-mode emulation on an x86 host. The kernel's binfmt_misc handler hands arm64 binaries to qemu-aarch64, which translates each instruction at run time. CPU-heavy steps such as compiling native addons, running a bundler or installing thousands of packages are commonly 5 to 20 times slower this way, and the emulator occasionally crashes on workloads with heavy threading or JIT compilation, which Node.js does a lot of. The segfault came from QEMU, not from our code.

What is happening under the hood

When you run docker buildx build --platform linux/amd64,linux/arm64, BuildKit builds each platform separately and then pushes one manifest list (an OCI image index) that points at both platform images. Where each platform is built depends on the builder:

  • With a single builder node on an amd64 host, amd64 steps run natively and arm64 steps run through QEMU.

  • With a builder that has an amd64 node and an arm64 node, each platform runs natively on its own node.

  • With separate CI jobs on native runners, each job builds one platform and a final job merges the results.

Cross-compilation is a fourth option: run the compiler natively on the build platform and target the other architecture, using --platform=$BUILDPLATFORM in the FROM line and TARGETARCH in the build. It works very well for Go and Rust, less well for ecosystems that compile native modules during install, like Node.js and Python.

Environment

Component

Version / value

CI

GitHub Actions, GitHub-hosted runners

Build runner

ubuntu-24.04 (x86_64, 4 vCPU)

Build tool

Docker Buildx, docker/build-push-action@v6, docker/setup-qemu-action@v3

Image

Node.js 22 on node:22-bookworm-slim, multi-stage

Native modules

bcrypt, sharp

Registry

GitHub Container Registry

Minimal reproduction

jobs:
  image:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
      - uses: docker/setup-qemu-action@v3
      - uses: docker/setup-buildx-action@v3
      - uses: docker/build-push-action@v6
        with:
          platforms: linux/amd64,linux/arm64
          push: true
          tags: ghcr.io/example-org/api:${{ github.sha }}

Who is affected

Anyone building multi-platform images on a single-architecture host with emulation, especially for interpreted runtimes that compile native extensions at install time (Node.js, Python wheels without prebuilt binaries, Ruby gems). Compiled-language builds that cross-compile are mostly unaffected.

The fix

We moved to one native runner per platform, pushed each platform image by digest (no tag), and merged the digests into a tagged manifest list in a final job. GitHub-hosted arm64 runners are available with the ubuntu-24.04-arm label (free for public repositories; on paid plans for private ones). The pattern follows Docker's documentation for distributing builds across runners.

jobs:
  build:
    strategy:
      matrix:
        include:
          - platform: linux/amd64
            runner: ubuntu-24.04
          - platform: linux/arm64
            runner: ubuntu-24.04-arm
    runs-on: ${{ matrix.runner }}
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v4
      - uses: docker/setup-buildx-action@v3
      - uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - id: build
        uses: docker/build-push-action@v6
        with:
          platforms: ${{ matrix.platform }}
          outputs: type=image,name=ghcr.io/example-org/api,push-by-digest=true,name-canonical=true,push=true
          cache-from: type=gha,scope=api-${{ runner.arch }}
          cache-to: type=gha,scope=api-${{ runner.arch }},mode=max
      - name: Export digest
        run: |
          mkdir -p /tmp/digests
          digest="${{ steps.build.outputs.digest }}"
          touch "/tmp/digests/${digest#sha256:}"
      - uses: actions/upload-artifact@v4
        with:
          name: digest-${{ runner.arch }}
          path: /tmp/digests/*
          retention-days: 1

  merge:
    needs: build
    runs-on: ubuntu-24.04
    permissions:
      packages: write
    steps:
      - uses: actions/download-artifact@v4
        with:
          path: /tmp/digests
          pattern: digest-*
          merge-multiple: true
      - uses: docker/setup-buildx-action@v3
      - uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Create manifest list
        working-directory: /tmp/digests
        run: |
          docker buildx imagetools create \
            -t ghcr.io/example-org/api:${{ github.sha }} \
            $(printf 'ghcr.io/example-org/api@sha256:%s ' *)

We removed docker/setup-qemu-action entirely, so no step can silently fall back to emulation.

On GitLab, the same pattern works with GitLab-hosted Arm runners (saas-linux-small-arm64 and larger sizes) or a self-managed arm64 runner pool, with the merge job running docker buildx imagetools create after both build jobs.

Alternatives and trade-offs

  • Cross-compile. For our Go services we kept a single job: FROM --platform=$BUILDPLATFORM golang:1.24 AS build plus GOARCH=$TARGETARCH go build. Fast and simple, but not practical for the Node image because native modules compile during npm ci.

  • Multi-node buildx builder. docker buildx create --append with an arm64 node reachable from CI gives native builds in one job. It needs a long-lived, secured remote builder.

  • Keep QEMU, reduce work under emulation. Move heavy steps to a stage pinned to $BUILDPLATFORM and copy platform-neutral outputs (bundled JS) into the target stage. Helps, but native modules still compile emulated.

  • Arm only. If every deployment target is arm64, build only arm64 natively and skip the merge step.

How to test the fix

Check the pushed tag has both platforms and that each image reports the right architecture:

docker buildx imagetools inspect ghcr.io/example-org/api:$SHA
Name:      ghcr.io/example-org/api:3f9c2e1
MediaType: application/vnd.oci.image.index.v1+json
Manifests:
  Name:      ghcr.io/example-org/api:3f9c2e1@sha256:9d1e...
  Platform:  linux/amd64
  Name:      ghcr.io/example-org/api:3f9c2e1@sha256:4b7a...
  Platform:  linux/arm64
docker run --rm --platform linux/arm64 ghcr.io/example-org/api:$SHA node -e "console.log(process.arch)"
# arm64

Confirming in production

The total workflow time dropped to 7 minutes: both legs run in parallel in about 5 minutes each, plus a 30-second merge. Over the next 200 runs we had zero segfaults. The arm64 node pool in Kubernetes pulled the same tag as amd64 nodes, and kubectl get pods -o wide with node labels confirmed pods were running on both architectures from one image reference.

Regression guard

  • The merge job fails if the manifest list does not contain exactly the expected platforms:

docker buildx imagetools inspect "$IMAGE" --format '{{json .Manifest}}' \
  | jq -r '.manifests[].platform | select(.os != "unknown") | "\(.os)/\(.architecture)"' \
  | sort | tr '\n' ' ' | grep -qx 'linux/amd64 linux/arm64 ' || { echo "unexpected platforms"; exit 1; }
  • A smoke test runs the image on each native runner before promotion.

  • A workflow lint rule rejects docker/setup-qemu-action in this repository.

The select(.os != "unknown") filter skips attestation manifests that BuildKit adds for provenance, which appear with platform unknown/unknown.

Security implications

Building natively removes the privileged binfmt setup step that registers emulators on the runner. Pushing by digest and tagging only in the merge job also means a tag never points at a half-finished, single-platform image. If you use self-hosted arm64 runners, give them the same isolation as amd64 runners: ephemeral where possible, no long-lived registry credentials, and OIDC or the job token for pushes.

Prevention checklist

  • Do not run CPU-heavy multi-arch builds under QEMU in CI.

  • Use native runners per platform, or cross-compile where the language allows.

  • Push platform images by digest; tag only the merged manifest list.

  • Verify the platforms in the manifest list before deploying.

  • Scope build caches per architecture.

References

Add a label

#docker #github-actions #buildx #arm64 #multi-arch #qemu
Written by
Ingrid Solberg @ingridsolberg

I work on performance and capacity for a marketplace with heavy read traffic and sharp daily peaks. My days are split between caches, Redis, document stores, connection pools and the load tests that tell us whether any of it will hold. Most of the problems I write about looked like scaling issues and turned out to be something smaller: a cache that refilled itself with stale data, a single command that froze Redis, a pool drained by one leaked connection, a load test that measured its own generator instead of the system. I try hard to measure before changing anything, so each post includes how we gathered numbers, what they showed and how we confirmed the fix under realistic load. I also include the optimisations that made things worse, because those taught me the most.

Advertisement

Comments

0

No comments yet. Be the first to comment!

Sign In to post a comment.