无法将python软件包下载到Docker映像上 [英] Can't download python packages onto Docker image

查看:169
本文介绍了无法将python软件包下载到Docker映像上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注官方文档这里

I have been following the official Docs here.

我的 Dockerfile app.py requirements.txt 与本教程中给出的相同。

当我尝试使用<$ c $构建我的Docker映像时c> docker build -t friendlyhello。 docker运行 RUN pip install -r requirements.txt 部分时,出现以下错误:

My Dockerfile, app.py and requirements.txt are same as that given in the tutorial.
When I try to build my Docker image using docker build -t friendlyhello . I get the following error while docker runs the RUN pip install -r requirements.txt section:


在连接被'NewConnectionError()断开后重试(Retry(total = 4,connect = None,read = None,redirect = None))建立新的连接:[Errno -2]名称或服务未知',)':/ simple / flask /

Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/flask/

I已经签出,并尝试了所有拟议的解决方案似乎没有

I have already checked out this and tried all the proposed solutions none seem to work.

预先感谢。

编辑1:我的要求。txt

Edit 1: My requirements.txt

烧瓶
Redis

完整的输出

Sending build context to Docker daemon 4.608 kB
Step 1/7 : FROM python:2.7-slim
---> 4ba53c70eb04
Step 2/7 : WORKDIR /app
---> Using cache
---> bebf675fc3bd
Step 3/7 : ADD . /app
---> Using cache
---> 435299812b68
Step 4/7 : RUN pip install -r requirements.txt
---> Running in 97465239272f
Collecting Flask (from -r requirements.txt (line 1))
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after       connection broken by'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f29c8b33910>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/flask/
Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f29c8bb9f90>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/flask/
Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f29c9aa69d0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/flask/
Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f29c9aa6190>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/flask/
Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f29c9aa6510>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/flask/
Could not find a version that satisfies the requirement Flask (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for Flask (from -r requirements.txt (line 1))
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

编辑2:我发现我的公司使用特定的DNS,通过它可以解析 docker run --dns [DNS] busybox nslookup google。 com

Edit 2: I found out my company uses a specific DNS using which I could resolve docker run --dns [DNS] busybox nslookup google.com

推荐答案

问题在于解析容器中的DNS。要解决该问题,请遵循有助于解决docker容器中DNS的过程:

The issue is in resolving the DNS in the containers. To resolve that follow the procedure which help to resolve the DNS in docker containers:

找出您机器中使用的DNS服务器:

# nm-tool  |grep DNS
    DNS:             172.24.100.50
    DNS:             10.1.100.50

使用在上述步骤中找到的可解决DNS问题的DNS IP再次运行它:

# docker run --dns 172.24.100.50 busybox nslookup google.com
Server:    172.24.100.50
Address 1: 172.24.100.50 indc01.radisys.com
Name:      google.com
Address 1: 2607:f8b0:4009:80c::200e ord36s01-in-x0e.1e100.net
Address 2: 172.217.4.110 ord36s04-in-f14.1e100.net

要解决它将以下内容永久添加到新文件中:

# cat /etc/docker/daemon.json
{
    "dns" : ["172.24.100.50", "8.8.8.8"]
}

有关Docker DNS配置的更多信息:> https://docs.docker.com/engine/userguide/networking/configure-dns/

More info on Docker DNS configuration : https://docs.docker.com/engine/userguide/networking/configure-dns/

重新启动docker服务并再次检查它:

# docker run busybox nslookup google.com
Server:    172.24.100.50
Address 1: 172.24.100.50 indc01.radisys.com
Name:      google.com
Address 1: 2607:f8b0:4009:801::200e ord30s31-in-x0e.1e100.net
Address 2: 172.217.4.238 ord30s31-in-f14.1e100.net

通过运行容器进行检查:

root@labadmin-VirtualBox:/home/labadmin# docker run -it e02e811dd08f
/ # ping google.com
PING google.com (172.217.4.238): 56 data bytes
64 bytes from 172.217.4.238: seq=0 ttl=47 time=251.506 ms
64 bytes from 172.217.4.238: seq=1 ttl=47 time=245.621 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 245.621/257.113/272.586 ms
/ #

这篇关于无法将python软件包下载到Docker映像上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆