docker build_error ai_generated true

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

ERROR: Service 'app' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

ID: docker/container-exit-code-1-during-build

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

版本兼容性

版本状态引入弃用备注
Docker 24.0.7 active
Docker 25.0.3 active
Docker 23.0.6 active

根因分析

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

English

A RUN command in Dockerfile fails, usually due to missing dependencies, network issues, or incorrect package versions.

generic

官方文档

https://docs.docker.com/engine/reference/builder/#run

解决方案

  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)

无效尝试

常见但无效的做法:

  1. 80% 失败

    Adding --no-cache-dir to pip install does not fix underlying package conflicts or network errors.

  2. 90% 失败

    Running the command manually inside a running container without the correct base image may succeed but fail during build due to different environment.