docker type_error ai_generated true

执行 /usr/bin/python3:执行格式错误

exec /usr/bin/python3: exec format error

ID: docker/exec-format-error-arm64

其他格式: JSON · Markdown 中文 · English
92%修复率
90%置信度
1证据数
2024-01-22首次发现

版本兼容性

版本状态引入弃用备注
Docker 25.0.0 active
containerd 1.7.10 active
Linux 6.5.0-arm64 active

根因分析

容器镜像是为不同 CPU 架构(如 amd64)构建的,而宿主是 arm64,导致二进制文件的 ELF 格式不兼容。

English

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

官方文档

https://docs.docker.com/build/building/multi-platform/

解决方案

  1. 拉取正确架构的镜像:'docker pull --platform linux/arm64 python:3.12-slim'。对于多架构构建,使用 'docker buildx build --platform linux/arm64 -t myapp .'
  2. 安装 QEMU 用户静态二进制文件以支持模拟:'docker run --privileged --rm tonistiigi/binfmt --install all'。然后使用 'docker run --platform linux/amd64 ...' 运行 amd64 镜像。

无效尝试

常见但无效的做法:

  1. Reinstall Docker on the host 95% 失败

    Reinstallation does not change the CPU architecture mismatch between image and host.

  2. Add '--platform linux/amd64' to docker run 80% 失败

    Forcing amd64 on an arm64 host without binfmt_misc or QEMU setup will still fail if the binary is not emulated.

  3. Update Python inside the container via pip 90% 失败

    The error is at the binary execution level, not Python version; pip cannot fix ELF format.