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