Skip to content

exec format error: multi-arch image with the wrong binary

Containertested on Docker 29.9.0, buildx v0.38.0

“exec format error” means the kernel cannot run the file because it was built for a different CPU architecture. With multi-arch images this is sneaky: the index lists every platform, but the arm64 variant contains an amd64 binary.

Symptom

docker buildx imagetools inspect localhost:5001/notes-api:r07 | grep Platform
  Platform:    linux/amd64
  Platform:    linux/arm64
  Platform:    unknown/unknown
  Platform:    unknown/unknown

The index lists both platforms. On arm64 servers the container still fails with exec format error, on amd64 it runs.

Diagnosis

Create the arm64 variant without starting it, copy the binary out and ask file – this works on any machine.

docker create --pull always --platform linux/arm64 --name notes-r07 \
  localhost:5001/notes-api:r07
docker cp notes-r07:/notes-api ./notes-api.bin
file notes-api.bin
notes-api.bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked…

Causes

GOARCH=amd64Target architecture hard-coded

With GOARCH=amd64 in the Dockerfile every run builds an amd64 binary – including the one for linux/arm64. buildx still files it under the arm64 label.

TARGETARCH missingBuild arguments not declared

BuildKit sets TARGETOS and TARGETARCH automatically, but they are only visible in a stage if an ARG declares them.

Fix

Run the compiler natively (--platform=$BUILDPLATFORM) and take the target platform from TARGETOS/TARGETARCH; then check again.
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS build
ARG TARGETOS TARGETARCH VERSION=dev
    CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
file notes-api.bin
notes-api.bin: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically…

Don't: Emulate the build under QEMU just to make GOARCH match – Go cross-compiles natively for every target and is many times faster that way.

▶
Break it yourself and find it – free
Dockerfiles hands-on, Day 15: diagnose and repair ten broken Dockerfiles against the clock.
Go to day 15 →

FAQ

What are the unknown/unknown entries in the index?

They are attestations (provenance, SBOM) that buildx attaches – not runnable variants.

Do I need an arm64 machine for multi-arch builds?

No. With --platform=$BUILDPLATFORM the Go compiler runs natively and cross-compiles the binary for the target platform.

Related error patterns

More