Fix "exec format error" in Docker (arm64 / amd64)
exec /usr/local/bin/docker-entrypoint.sh: exec format error
- standard_init_linux.go:228: exec user process caused: exec format error
- exec /app/server: exec format error
- WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
- exec /bin/sh: exec format error
The kernel cannot execute the launched file: most often the image was built for another architecture (arm64 on an Apple Silicon Mac, deployed to an amd64 server). Rebuild for the right platform with docker buildx build --platform linux/amd64, or fix the entrypoint script’s shebang.
What this error means
When the container starts, the runtime calls execve() on the entrypoint. The kernel reads the file header: an ELF binary must match the CPU (x86-64 or AArch64), and a script must start exactly with #! followed by an interpreter. If the binary targets another architecture and no QEMU emulation is registered, or if the script has no valid shebang (missing line, UTF-8 BOM before #!), the kernel returns ENOEXEC, shown as "exec format error". The container exits immediately with code 1 or 255.
Common causes
- Image built on Apple Silicon (arm64) then run on an x86-64 (amd64) server or CI runner, or the other way round.
- Binary downloaded or compiled for the wrong architecture in the Dockerfile (hard-coded
linux-amd64URL, fixedGOARCH). - Script without a shebang or with a BOM:
docker-entrypoint.shdoes not start with#!/bin/sh, or the editor added an invisible UTF-8 BOM before it. - No emulation on Linux:
--platform linux/arm64on an amd64 host without QEMU/binfmt registered.
Step-by-step fix
-
Compare image and host architecture
uname -mprintsx86_64(amd64) oraarch64/arm64. If the image shows another architecture, that is the cause.uname -m docker image inspect --format '{{.Os}}/{{.Architecture}}' myapp:latest -
Build for the target platform
On an Apple Silicon Mac, target the server explicitly. For an image that runs everywhere, build both architectures and push a multi-platform manifest.
docker buildx build --platform linux/amd64 -t myapp:latest --load . docker buildx build --platform linux/amd64,linux/arm64 \ -t registry.example.com/myapp:1.0 --push . -
Make the Dockerfile architecture-independent
Use the
TARGETARCHvariable provided by BuildKit (amd64,arm64) instead of a hard-coded architecture for downloaded or compiled binaries.FROM --platform=$BUILDPLATFORM golang:1.23 AS build ARG TARGETOS TARGETARCH WORKDIR /src COPY . . RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /out/server . FROM alpine:3.20 COPY --from=build /out/server /usr/local/bin/server ENTRYPOINT ["/usr/local/bin/server"] -
Run a foreign image with emulation
To run an amd64 image on arm64 (or the reverse), specify the platform. Docker Desktop already emulates; on Linux, register QEMU once (privileged command, run it on a trusted machine).
docker run --privileged --rm tonistiigi/binfmt --install all docker run --rm --platform linux/amd64 myapp:latest -
Check the script’s shebang and encoding
The
filecommand reports a BOM ("with BOM") or CRLF line endings. The first line must be exactly#!/bin/shor#!/usr/bin/env bash. Note: a CRLF shebang usually gives "no such file or directory" instead, but is fixed the same way.file docker-entrypoint.sh head -n 1 docker-entrypoint.sh | od -c | head -n 2 -
Clean the script in the image
Strip the BOM and CRLF at build time and make the script executable. Also add a
.gitattributesrule so Git on Windows does not bring CRLF back.COPY docker-entrypoint.sh /usr/local/bin/ RUN sed -i -e '1s/^\xEF\xBB\xBF//' -e 's/\r$//' /usr/local/bin/docker-entrypoint.sh \ && chmod +x /usr/local/bin/docker-entrypoint.sh # .gitattributes: *.sh text eol=lf
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- Pin the platform in
compose.yaml(platform: linux/amd64) or always build multi-platform in CI. - Use
TARGETARCHin Dockerfiles and choose multi-architecture base images (official images). - Add
*.sh text eol=lfto.gitattributesand set the editor to UTF-8 without BOM.
Frequently asked questions
Why does my image work on my M1/M2/M3 Mac but not on the server?
It was built as arm64, the Mac’s architecture. The server is amd64 and cannot run it without emulation. Rebuild with --platform linux/amd64 or multi-platform.
How do I know which architecture a binary is compiled for?
Use file ./binary: it prints for example "ELF 64-bit LSB executable, x86-64" or "ARM aarch64".
Is QEMU emulation good enough in production?
It works but is much slower and sometimes unstable. In production, use an image native to the server’s architecture.
Useful tools for this error
More Docker & DevOps errors
- Fix "permission denied while trying to connect to the Docker daemon socket"
- Fix "Bind for 0.0.0.0:8080 failed: port is already allocated" (Docker)
- Fix "no space left on device" (Docker and Linux)
- Fix "Cannot connect to the Docker daemon. Is the docker daemon running?"
- Fix "connect() failed (111: Connection refused) while connecting to upstream" (Nginx 502)
- Fix "exited with code 137" (OOMKilled) in Docker and Kubernetes
- Fix "CrashLoopBackOff" / "Back-off restarting failed container" (Kubernetes)