无法将Python包下载到Docker镜像上

我一直在这里跟踪官方文件。

我的Dockerfileapp.pyrequirements.txt与本教程中给出的相同。
当我尝试使用docker build -t friendlyhello .构buildDocker镜像时docker build -t friendlyhello . docker运行RUN pip install -r requirements.txt部分时出现以下错误:

)连接断开连接后,重试(重试(总= 4,连接=无,读取=无,redirect=无)))NewConnectionError(':无法build立新的连接:[Errno -2] Name or service not known' ':/ simple / flask /

我已经检查了这一点,并尝试所有build议的解决scheme似乎没有工作。

提前致谢。

编辑1:我的requirements.txt

Flask 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

如果您需要更新守护程序以使用不同的DNS地址,则可以使用以下命令创build(或修改)/etc/docker/daemon.json文件:

 { "dns": ["8.8.8.8", "8.8.2.2"] } 

只要将上面的IPreplace成你自己的需求,当完成后,你可以在你的守护进程上运行重新加载或重新启动来重新读取文件。

 sudo systemctl reload docker 

这应该更改所有新容器的默认DNS,包括构build时使用的那些容器。

请参阅以下链接,了解可在此文件中设置的更多详细信息: https : //docs.docker.com/engine/reference/commandline/dockerd/#linux-configuration-file

问题在于解决容器中的DNS问题。 要解决该问题,请按照帮助解决Docker容器中的DNS的步骤进行操作:

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

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

再次使用DNS解决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 DNSconfiguration的更多信息: 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 / #