docker
type_error
ai_generated
true
exec /usr/bin/python3: exec format error
ID: docker/exec-format-error-arm64
92%Fix Rate
90%Confidence
1Evidence
2024-01-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Docker 25.0.0 | active | — | — | — |
| containerd 1.7.10 | active | — | — | — |
| Linux 6.5.0-arm64 | active | — | — | — |
Root Cause
The container image is built for a different CPU architecture (e.g., amd64) than the host (e.g., arm64), causing the binary's ELF format to be incompatible.
generic中文
容器镜像是为不同 CPU 架构(如 amd64)构建的,而宿主是 arm64,导致二进制文件的 ELF 格式不兼容。
Official Documentation
https://docs.docker.com/build/building/multi-platform/Workarounds
-
95% success Pull the correct architecture image: 'docker pull --platform linux/arm64 python:3.12-slim'. For multi-arch builds, use 'docker buildx build --platform linux/arm64 -t myapp .'
Pull the correct architecture image: 'docker pull --platform linux/arm64 python:3.12-slim'. For multi-arch builds, use 'docker buildx build --platform linux/arm64 -t myapp .'
-
85% success Install QEMU user static binaries for emulation: 'docker run --privileged --rm tonistiigi/binfmt --install all'. Then run the amd64 image with 'docker run --platform linux/amd64 ...'
Install QEMU user static binaries for emulation: 'docker run --privileged --rm tonistiigi/binfmt --install all'. Then run the amd64 image with 'docker run --platform linux/amd64 ...'
中文步骤
拉取正确架构的镜像:'docker pull --platform linux/arm64 python:3.12-slim'。对于多架构构建,使用 'docker buildx build --platform linux/arm64 -t myapp .'
安装 QEMU 用户静态二进制文件以支持模拟:'docker run --privileged --rm tonistiigi/binfmt --install all'。然后使用 'docker run --platform linux/amd64 ...' 运行 amd64 镜像。
Dead Ends
Common approaches that don't work:
-
Reinstall Docker on the host
95% fail
Reinstallation does not change the CPU architecture mismatch between image and host.
-
Add '--platform linux/amd64' to docker run
80% fail
Forcing amd64 on an arm64 host without binfmt_misc or QEMU setup will still fail if the binary is not emulated.
-
Update Python inside the container via pip
90% fail
The error is at the binary execution level, not Python version; pip cannot fix ELF format.