Docker课程教程,python pip失败

我正在关注https://docker-curriculum.com/中的教程来生成我的第一个Docker镜像。 在第2.4节中,我们将学习如何使用基本图像python:3-onbuildconfiguration一个简单的Dockerfile python:3-onbuild将自动运行pip并从requirements.txt安装依赖关系。

问题是,当我试图build立docker,包只是无法加载:

 mgitt@mgpc:~/workspace/docker-curriculum/flask-app$ docker build -t prakhar1989/catnip . Sending build context to Docker daemon 8.704kB Step 1/3 : FROM python:3-onbuild # Executing 3 build triggers... Step 1/1 : COPY requirements.txt /usr/src/app/ ---> Using cache Step 1/1 : RUN pip install --no-cache-dir -r requirements.txt ---> Running in 74c4e94fa1ba 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 0x7fc6592831d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /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 0x7fc659283cc0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /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 0x7fc659283208>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /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 0x7fc659283470>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /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 0x7fc659283ba8>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /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 --no-cache-dir -r requirements.txt' returned a non-zero code: 1 mgitt@mgpc:~/workspace/docker-curriculum/flask-app$ 

我已经看了这个计算器解决scheme 。 这些答案似乎已经解决了许多人无法连接域名服务器(DNS)的问题,但重置docker或添加到/etc/dhcp/dhclient.conf的DNS没有为我做任何事情。

我已经安装了Docker 17.09.0-ce版本,并在Ubuntu 16.04上运行,有什么想法?

如果您正在使用代理。 docker集装箱很可能根本无法到达互联网。

你可以通过运行来testing

 $ docker run -it busybox sh / # ping google.com 

如果它挂起,你知道你有一个问题。 现在我们必须find你的主机用来连接互联网的networking接口。 ipconfig会给你一个名称列表,无论哪一个用于连接到互联网是你的IFACENAME。 现在运行:

 $ nmcli dev list | grep 'IP4.DNS' # Ubuntu <= 14 $ nmcli device show IFACENAME | grep IP4.DNS # Ubuntu >= 15 

这将列出您的代理服务器所在的IP_ADDRESS。 可能有一个以上,只是使用第一个。 使用以下内容创build文件/etc/docker/daemon.json

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

最后,

 $ sudo service docker restart 

你现在应该能够从一个容器中ping通。