Skip to content
Latchkey

Docker "exec format error" from wrong architecture in CI

The kernel tried to run a binary built for a different CPU architecture. An arm64 image on an amd64 runner (or vice versa) without emulation produces this exact error.

What this error means

A RUN step or container start fails with exec format error or exec /bin/sh: exec format error. It only happens on a host whose architecture differs from the image.

docker
exec /bin/sh: exec format error
ERROR: process "/bin/sh -c ./build.sh" did not complete successfully: exec format error

Common causes

Image architecture differs from the host

An arm64 base or arm64-built binary is run on an amd64 runner without emulation, or vice versa.

No QEMU registered for cross-build

A multi-arch buildx build runs foreign-arch steps but QEMU binfmt was never set up.

Wrong --platform pin

A platform was forced that the host cannot execute natively.

How to fix it

Set up emulation and buildx

  1. Register QEMU binfmt so foreign-arch steps can run.
  2. Use a buildx builder for multi-platform builds.
.github/workflows/build.yml
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3

Build for the host architecture

  1. Pin --platform to the runner architecture when you do not need cross-arch.
  2. Or build a true multi-platform image with buildx.
Terminal
docker build --platform linux/amd64 -t app .

How to prevent it

  • Match the build platform to the runner, and set up QEMU + buildx whenever you build or run images for a different architecture.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →