[英]ConnectTimeoutError while running 'pip install' via docker-compose
I'm new to docker and currently trying to build an image for my Django project.我是 docker 的新手,目前正在尝试为我的 Django 项目构建映像。 Here's my
Dockerfile
:这是我的
Dockerfile
:
FROM python:3.8.5-alpine
WORKDIR /my_project
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt
COPY . .
When I run docker-compose build
, execution breaks at the second pip command with the following error;当我运行
docker-compose build
时,执行在第二个 pip 命令处中断,并出现以下错误;
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f2b21bd1610>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/asgiref/
警告:在连接被“ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f2b21bd1610>, '与 pypi.org 的连接超时。(连接超时 = 15)')':/simple/asgiref/
Some Context:一些背景:
OS : Ubuntu 20.04.1 LTS Kernel : Linux 5.8.0-34-generic操作系统:Ubuntu 20.04.1 LTS Kernel :Linux 5.8.0-34-通用
docker --version
Docker version 20.10.2, build 2291f61 docker --version
Docker 版本 20.10.2, build 2291f61
docker-compose --version
docker-compose version 1.27.4, build 40524192 docker-compose --version
docker-compose 版本 1.27.4,构建 40524192
I have gone through a lot of similar questions online but none of their corresponding solutions work for me.我在网上经历了很多类似的问题,但他们相应的解决方案都不适合我。 I'll be more than glad to share any other info needed to assist in troubleshooting.
我非常乐意分享帮助排除故障所需的任何其他信息。
Sound there is some issue with the network connectivity while build the docker container.声音在构建 docker 容器时网络连接存在一些问题。 Use
Host
as an network inside compose file to resolve the issue.使用
Host
作为 compose 文件中的网络来解决问题。
version: '3.4'
services:
django_image:
build:
context: .
network: host
Give it a try and it will solve the issue.试一试,它会解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.