Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

Docker "exec format error" and "does not match the detected host platform": wrong CPU architecture or a file that cannot run

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

When a container stops with exec /usr/local/bin/app: exec format error, the kernel refused to run the first file of the container. The usual cause is an image built for a different CPU architecture from the host, often with a warning that the requested image's platform "does not match the detected host platform". The other cause is an entry script with no valid first line. Compare the two platforms first.

What the error means

The kernel's execve(2) manual page lists the error ENOEXEC and says the file "is not in a recognized format, is for the wrong architecture, or has some other format error that means it cannot be executed". In Go, which runc is written in, that error number prints as exec format error. The runc v1.2.2 source wraps a failed exec as an error with the operation exec, the path and the error text, which gives the form exec /path: exec format error.

Docker's multi-platform page explains the architecture case: containers share the host kernel, so code in a container must suit the host's architecture, and "you can't run a linux/amd64 container on an arm64 host (without using emulation)". A multi-platform image holds a manifest list, and Docker picks the variant that matches the host. A single-platform image offers no choice.

The warning comes from the Docker daemon. In moby v27.3.1, when no platform was requested and the image's platform does not match the host's, the daemon adds a warning with the fixed words "does not match the detected host platform" and "and no specific platform was requested", and the client prints it after WARNING:. The warning does not stop the container; the failure that follows does.

The same manual page names a second route to the same error: an interpreter script is "a text file that has execute permission enabled and whose first line is of the form" #!interpreter. A script used as an entry point without that line is not in a recognised format.

Likely causes

Cause What you see How to confirm
The image was built for another architecture only The warning names two platforms, then the container exits The platform list for the image does not include the host's platform
A platform was forced The warning is absent, the forced platform differs from the host --platform on the command line or platform: in the compose file
A binary inside the image targets another architecture Image platform equals the host's, error persists The Dockerfile copies in a binary built outside the image, for another target
The entry script has no #! first line exec /entrypoint.sh: exec format error The first line of the script is not #! and an interpreter
The image is for another operating system The image's Os differs from the server's Docker's multi-platform page says such a container cannot run ("a Windows container on a Linux host"); it does not say which message appears

Prove the cause before changing anything

All of these read only.

1. Which platform is the host? Docker's reference pages show docker version printing an OS/Arch line for the server, such as linux/amd64, and docker system info printing OSType and Architecture:

docker version
docker system info

2. Which platform is the image? The Engine API definition lists Architecture, Variant and Os in the image's data:

docker inspect registry.example.com/app:2.0

A good result is Os and Architecture that match step 1. Read Architecture with care: Docker's info page prints values such as x86_64 and aarch64, while image data and Platform: lines use Go-style names such as amd64 and arm.

3. What does the registry offer? Docker's reference shows docker buildx imagetools inspect listing the manifests of an image with a Platform: line for each:

docker buildx imagetools inspect registry.example.com/app:2.0

A single manifest for the wrong platform means the build produced no variant for this host. A manifest list that includes the host's platform means something forced the wrong choice: look at step 4.

4. Was a platform forced? Search the docker run line for --platform and the compose file for platform:. Docker's run reference describes --platform as "Set platform if server is multi-platform capable", and the Compose specification says platform "defines the target platform the containers for the service run on" using the os[/arch[/variant]] syntax.

5. Is the entry script valid? In the build context, print the first line of the script that the Dockerfile's ENTRYPOINT or CMD runs:

head -n 1 entrypoint.sh

A good result starts with #! followed by an interpreter path. A blank, a comment or code on line 1 is a bad result.

Fix

Choose by cause. Keep the platforms the same on both sides rather than hiding the mismatch.

The image has no variant for the host

Building does not change running containers; it writes an image or cache. Docker's multi-platform page says to use --platform to define the target platforms of a build. Such builds need an image store that supports manifest lists (the containerd image store, the default from Docker Engine 29.0) or a builder that uses the docker-container driver, whose images "aren't loaded into your Docker Engine image store" and are pushed to a registry instead. The page's example:

docker buildx build --platform linux/amd64,linux/arm64 .

The page notes that emulation with QEMU "can be much slower than native builds", so building each platform natively is faster than emulating. Running a non-native image through QEMU is possible but needs emulators registered on the host, which changes the host. The page documents that registration for builds and gives no step to undo it, so no command for it is given.

A platform is forced wrongly

First save the current state:

cp -p compose.yaml compose.yaml.2026-12-02
docker compose config > config-before.yaml

Risk: the next edit changes or removes the platform: line of the compose service. The service then asks for another variant of the image, and a later docker compose up recreates its container.

Edit compose.yaml so that platform: matches the host, or delete the line where the host's own platform is wanted. Then check the rendered file with docker compose config.

To undo it: copy the saved file back, and confirm the rendered model matches the saved one.

cp -p compose.yaml.2026-12-02 compose.yaml
docker compose config > config-restored.yaml
diff config-before.yaml config-restored.yaml

The entry script has no valid first line

First save the current state:

cp -p entrypoint.sh entrypoint.sh.2026-12-02

Risk: the next edit adds a first line to the entry script of the image. The script then runs under the interpreter you name. The rebuild that follows creates a new image; a service that uses the same tag runs the new image the next time its container is recreated, so build under a new tag.

Add a first line such as #!/bin/sh that names an interpreter the image contains, then rebuild the image under a new tag. The service is pointed at the new tag only after that build succeeds, by editing its image: line in the compose file, which needs its own saved copy first.

To undo it: copy the saved script back, rebuild, and point the service back at the tag it used before; note that tag now, before any edit.

cp -p entrypoint.sh.2026-12-02 entrypoint.sh

Example (illustrative): docker01 reports Architecture: x86_64 in docker system info, and docker version shows OS/Arch: linux/amd64 for the server. docker run registry.example.com/app:2.0 prints WARNING: with the words "does not match the detected host platform" and the container exits with exec /usr/local/bin/app: exec format error. docker buildx imagetools inspect registry.example.com/app:2.0 lists one manifest, Platform: linux/arm64. The administrator asks the image's maintainer for a build that includes linux/amd64, built with --platform linux/amd64,linux/arm64, and a new tag 2.1.

Confirm the fix

  1. docker buildx imagetools inspect on the new tag lists a Platform: entry equal to the host's OS/Arch.
  2. The run or docker compose up no longer prints the platform warning.
  3. docker container ls shows the container as Up for longer than the old exit time, and the logs show the application starting.

What to watch afterwards

  • Add the platform list to the release check for each image tag. A new tag can drop a platform.
  • A mixed fleet of x86-64 and arm64 hosts needs a manifest list; a single-platform image fails on one half.
  • Do not copy a binary built on a laptop into an image without checking its target.

Risks and limits

  • These commands have not been run or lab-tested.
  • Where the message appears, in the docker run output or the container's logs, can vary; check both.
  • Docker's pages name Architecture values in info and in image data in different styles; compare their meaning, not their spelling.
  • The daemon's warning text is a reading of moby v27.3.1; newer releases may word it differently.

Sources