简体   繁体   English

pip 安装在 docker 容器内不起作用

[英]pip install not working inside docker container

I have created a small project in flask and I am trying to deploy it using docker.我在 flask 中创建了一个小项目,我正在尝试使用 docker 部署它。 For this I have created my Dockerfile that looks like following:为此,我创建了 Dockerfile,如下所示:

FROM python:3.6-stretch

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app 
ADD . /app

# Install the dependencies
RUN pip install --user -r requirements.txt

# run the command to start uWSGI
CMD ["uwsgi", "app.ini"]

My requirements.txt file contains the following:我的 requirements.txt 文件包含以下内容:

#click==7.1.1
Flask==1.1.2
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
uWSGI==2.0.18
Werkzeug==1.0.1

I tried to build my project using docker-build with --network=host option and also usingdocker-compose, but have not been successful.我尝试使用带有 --network=host 选项的 docker-build 以及使用 docker-compose 来构建我的项目,但没有成功。 I get the following error:我收到以下错误:

    WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fac273160f0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/flask/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fac27316588>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/flask/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fac27316828>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/flask/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fac273166a0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/flask/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fac273168d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/flask/
ERROR: Could not find a version that satisfies the requirement Flask==1.1.2 (from -r requirements.txt (line 2)) (from versions: none)
ERROR: No matching distribution found for Flask==1.1.2 (from -r requirements.txt (line 2))

I have no clue why I am getting this error.我不知道为什么会收到此错误。 Can somebody help me with this?有人可以帮我吗? I am running docker-compose build command inside python virtual environment.我在 python 虚拟环境中运行 docker-compose 构建命令。

Your container can't connect to the internet while installing pip, so you need to fix this.您的容器在安装 pip 时无法连接到 Internet,因此您需要解决此问题。 I assume removing proxy from your docker file should fix this.我假设从您的 docker 文件中删除代理应该可以解决此问题。

I have solved this problem.我已经解决了这个问题。 I had to create a file /etc/docker/daemon.json and add the following section:我必须创建一个文件 /etc/docker/daemon.json 并添加以下部分:

{
  "dns": ["myDNS"]
}

The value of myDNS was obtained using the following: myDNS 的值是通过以下方式获得的:

nmcli dev show | grep 'DNS'

After that I restarted my docker and was able to install the dependencies.之后我重新启动了我的 docker 并能够安装依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM