【发布时间】:2022-10-23 20:11:56
【问题描述】:
尝试在RUN pip install -r requirements.txt 步骤上构建 docker 映像失败,并出现以下错误:
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/asgiref/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/asgiref/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/asgiref/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/asgiref/`
出于某种原因,asgiref==3.5.2 不想安装。这可能是什么原因?
使用的系统:
- 操作系统:Windows 11
- 搭载 Ubuntu 22.04 的 WSL 2
- Docker 版本 20.10.19,构建 d85ef84
- Dockerfile 内容:
# Pull base image
FROM python:3.10.6-slim-bullseye
# Set enviroment variables
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set work directory
WORKDIR /code
# Install dependencies
COPY ./requirements.txt .
RUN pip install -r requirements.txt
# Copy project
COPY . .
- requirements.txt 内容:
asgiref==3.5.2
Django==4.1.2
sqlparse==0.4.3
【问题讨论】:
-
您在尝试连接到
pypi.org时遇到超时错误。可能与防火墙有关吗?这是否适用于您可能制定了网络安全策略的工作? -
您还可以尝试在运行
pip时使用--default-timeout=100之类的东西来增加超时。 -
@michjnich 感谢您的编辑和您的 cmets。出于某种原因,现在它显示以下内容:
ERROR: Could not find a version that satisfies the requirement asgiref==3.5.2 (from versions: none) ERROR: No matching distribution found for asgiref==3.5.2 -
@michjnich 太荒谬了,Python 和 PIP 版本与虚拟环境中使用的相同,django4 以及 asgiref 安装得很好。不知道是什么问题......
-
这是在运行
docker build .时?我将您的 2 个文件复制到一个空项目中,它对我来说很好。如果是在本地,您只需确保您使用的是正确的版本...python --version- asgiref 3.5.2 需要 3.7 及更高版本。
标签: python django docker windows-subsystem-for-linux docker-build