Docker exec format error from an Apple Silicon build
THE SHORT ANSWER
exec format error means the Linux kernel refused to run the container's program because it isn't in a format that machine can execute. The usual cause: the image was built on an Apple Silicon Mac, so it holds linux/arm64 binaries, and the server is x86-64 (linux/amd64). Rebuild for the server with docker buildx build --platform linux/amd64, or publish a multi-platform image for both. If the architectures already match, the program is probably a script without a #! line at the very top; a script saved with Windows line endings fails with "no such file or directory" instead.
What does exec format error mean?
The container exits the moment it starts, with one line in its logs:
exec /usr/local/bin/docker-entrypoint.sh: exec format error
The path is whatever your ENTRYPOINT or CMD starts, such as exec /app/server: exec format error. The container runtime (runc) asked the kernel to run that file and got ENOEXEC back. The execve(2) man page defines it: “An executable is not in a recognized format, is for the wrong architecture, or has some other format error that means it cannot be executed.”
That covers two different problems. “Wrong architecture” is the Apple Silicon case below. “Some other format error” is usually a script with no #! line. If you started the container yourself, Docker may also have warned you first:
WARNING: The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested
The platform strings vary by machine; the wording is the same. Docker's docs put the rule simply: you “can't run a linux/amd64 container on an arm64 host (without using emulation)”, and the reverse holds too.
How do I check the architectures?
Compare the image with the machine that runs it:
# on the server
uname -m
# x86_64 -> linux/amd64
# aarch64 -> linux/arm64
# a local image
docker image inspect --format '{{.Os}}/{{.Architecture}}' myapp:latest
# linux/arm64
# an image in a registry: lists every platform it was published for
docker buildx imagetools inspect registry.example.com/myapp:latestOn an Apple Silicon Mac, uname -m prints arm64. If the image says linux/arm64 and the server says x86_64, you've found it.
Why does a Mac build produce the wrong image?
Because Docker builds for the machine it runs on unless told otherwise. The docker buildx build reference: “The default value is the platform of the BuildKit daemon where the build runs.” On an M-series Mac that's linux/arm64. The image runs perfectly on your laptop, gets pushed to a registry, and fails the first time an x86-64 server pulls it.
How do I build for linux/amd64?
Pass the server's platform to the build:
docker buildx build --platform linux/amd64 -t registry.example.com/myapp:1.0 --push .
To make it the default for every command that takes --platform, set the DOCKER_DEFAULT_PLATFORM environment variable in your shell:
export DOCKER_DEFAULT_PLATFORM=linux/amd64
On a Mac this build runs under emulation. Docker Desktop supports that by default, with no configuration, but expect it to be slow. Docker's docs: “Emulation with QEMU can be much slower than native builds, especially for compute-heavy tasks like compilation and compression or decompression.”
Also look for a hard-coded platform in the Dockerfile. FROM --platform=linux/arm64 ... pins that stage to arm64 whatever you pass on the command line, and some base images are only published for one architecture; imagetools inspect on the base image shows which.
Can one image run on both?
Yes. A multi-platform image holds a variant per architecture, and Docker pulls the one that matches the host. Build both and push them under one tag:
docker buildx build --platform linux/amd64,linux/arm64 -t registry.example.com/myapp:1.0 --push .
This needs an image store that understands manifest lists. Per Docker's docs, Docker Desktop and Docker Engine 29.0+ use the containerd image store by default, so it works without setup. On older engines you can use a builder with the docker-container driver instead, but its images “aren't loaded into your Docker Engine image store”, so push them straight to a registry.
Cross-compile instead of emulating
For compiled languages, emulation is the slow path. Docker's docs show running the build stage on your own platform and letting the compiler target the other one, using the automatic BUILDPLATFORM, TARGETOS and TARGETARCH build arguments. Their Go example:
# syntax=docker/dockerfile:1
FROM --platform=$BUILDPLATFORM golang:alpine AS build
ARG TARGETOS
ARG TARGETARCH
WORKDIR /app
COPY . .
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o server .
FROM alpine
COPY --from=build /app/server /server
ENTRYPOINT ["/server"]The same mistake happens without Docker's help: a binary built with plain go build on a Mac is a macOS arm64 program, and copying it into a Linux image fails with exec format error. Build it with GOOS=linux GOARCH=amd64 go build, or build inside the Dockerfile as above.
The architectures match: is it a script without #!?
The other common cause has nothing to do with CPUs. execve only runs a binary or “a script starting with a line of the form: #!interpreter [optional-arg]”. An entrypoint script that starts with a comment, a blank line or straight into commands has no interpreter line, so the kernel refuses it with the same ENOEXEC. In your terminal the script probably ran fine, because shells like bash fall back to running such files as shell scripts. The container runtime doesn't.
Put the interpreter on the very first line, with nothing before it:
#!/bin/sh set -e # migrations, config, etc. exec "$@"
Pick an interpreter the image has. Alpine-based images have /bin/sh but not /bin/bash, and a missing interpreter gives a different error, covered next.
no such file or directory for a file that exists
A script saved with Windows line endings fails with a confusing message instead of exec format error:
exec /entrypoint.sh: no such file or directory
The file exists. Its first line is #!/bin/sh followed by an invisible carriage return, so the kernel looks for an interpreter literally named /bin/sh\r. execve(2) lists that case under ENOENT: “path or a script or ELF interpreter does not exist.” Check for the \r:
head -1 entrypoint.sh | od -c # 0000000 # ! / b i n / s h \r \n
Fix it in the repo so it stays fixed. Git's gitattributes docs use exactly this example, then renormalize the files Git already has:
# .gitattributes *.sh text eol=lf git add --renormalize . git commit -m "Use LF line endings for shell scripts"
As a stopgap you can strip the carriage returns in the Dockerfile with RUN sed -i 's/\r$//' /entrypoint.sh.
What happens on EthioDeploy?
EthioDeploy builds your image from the GitHub repo on its own build servers, which are x86-64 like the servers your app runs on. An image built on your Mac never gets there, so the usual Apple Silicon case can't happen. It can still come from the repo itself: a Dockerfile stage pinned with FROM --platform=linux/arm64, a base image only published for arm64, or a binary compiled on your Mac and committed. Remove the pin, pick a multi-platform base image, or build the binary in the Dockerfile.
With the Builder setting on Auto, a repo with a Dockerfile is built from it; otherwise the stack is detected and built for you, with no Dockerfile involved. The shebang and line-ending problems still apply to any script your ENTRYPOINT or CMD runs. See how deploys work for the Builder options and the port your app has to listen on.
Questions
The kernel couldn't execute the container's program. Usually the image was built for another CPU architecture, such as linux/arm64 on an Apple Silicon Mac running on an x86-64 server. Otherwise the program is a script without a #! interpreter line at the top.
Run docker buildx build --platform linux/amd64 -t your-image --push . or set DOCKER_DEFAULT_PLATFORM=linux/amd64. The build runs under emulation on the Mac, so it is slower than a native build.
For a local image, docker image inspect --format '{{.Os}}/{{.Architecture}}' image:tag. For an image in a registry, docker buildx imagetools inspect image:tag lists every platform it was published for. Compare it with uname -m on the server.
Yes. Build with --platform linux/amd64,linux/arm64 and push. The result is a multi-platform image, and each host pulls the variant for its own architecture.
It has Windows line endings, so the kernel looks for an interpreter named /bin/sh followed by a carriage return. Convert the file to LF and add *.sh text eol=lf to .gitattributes. The same message appears when the #! line names an interpreter the image doesn't have, such as /bin/bash on Alpine.
Sources
Checked on November 15, 2026:
- Docker: Multi-platform builds
- Docker: docker buildx build
- Docker: docker buildx imagetools inspect
- Docker: docker image inspect
- Docker: CLI environment variables
- Docker: Dockerfile reference
- Linux man pages: execve(2)
- Linux man pages: uname(1)
- runc: internal/linux/linux.go
- moby: daemon/create.go
- Git: gitattributes
- Go: Installing Go from source ($GOOS and $GOARCH)
Push a repo. Get a URL.
Start freeJoin the EthioDeploy Telegram
Release notes as they ship, plus deploy help from the team and other developers.