docker build_error ai_generated true

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

Also available as: JSON · Markdown · 中文
82%Fix Rate
88%Confidence
1Evidence
2024-01-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Docker 24.0.7 active
Docker 25.0.3 active
Docker 23.0.6 active

Root Cause

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

generic

中文

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

Official Documentation

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

Workarounds

  1. 85% success 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.
    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. 75% success If network issues, add a retry mechanism in the RUN command: RUN pip install -r requirements.txt || (sleep 5 && pip install -r requirements.txt)
    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. 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)

Dead Ends

Common approaches that don't work:

  1. 80% fail

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

  2. 90% fail

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