# 错误：服务 'app' 构建失败：命令 '/bin/sh -c pip install -r requirements.txt' 返回了非零退出码：1

- **ID:** `docker/container-exit-code-1-during-build`
- **领域:** docker
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

Dockerfile 中的 RUN 命令失败，通常由于缺少依赖、网络问题或软件包版本不正确。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Docker 24.0.7 | active | — | — |
| Docker 25.0.3 | active | — | — |
| Docker 23.0.6 | active | — | — |

## 解决方案

1. ```
   Check the specific error message in the build output (e.g., 'Could not find a version that satisfies the requirement'). Then update requirements.txt or base image. Example: use 'pip install --upgrade pip' before installing requirements.
   ```
2. ```
   If network issues, add a retry mechanism in the RUN command: RUN pip install -r requirements.txt || (sleep 5 && pip install -r requirements.txt)
   ```

## 无效尝试

- **** — Adding --no-cache-dir to pip install does not fix underlying package conflicts or network errors. (80% 失败率)
- **** — Running the command manually inside a running container without the correct base image may succeed but fail during build due to different environment. (90% 失败率)
