# 执行 /usr/bin/python3：执行格式错误

- **ID:** `docker/exec-format-error-arm64`
- **领域:** docker
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

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

## 版本兼容性

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

## 解决方案

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 镜像。
   ```

## 无效尝试

- **Reinstall Docker on the host** — Reinstallation does not change the CPU architecture mismatch between image and host. (95% 失败率)
- **Add '--platform linux/amd64' to docker run** — Forcing amd64 on an arm64 host without binfmt_misc or QEMU setup will still fail if the binary is not emulated. (80% 失败率)
- **Update Python inside the container via pip** — The error is at the binary execution level, not Python version; pip cannot fix ELF format. (90% 失败率)
