2017-10-11 95 views
3

我按照https://docker-curriculum.com/中的教程生成我的第一個Docker鏡像。在第2.4節中,我們將學習如何使用基本映像python:3-onbuild來配置一個簡單的Dockerfile,它將自動運行pip並安裝requirements.txt的依賴關係。Docker課程教程,python pip失敗

的問題是,當我嘗試建立搬運工,包裝簡單地加載失敗:

[email protected]:~/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 
[email protected]:~/workspace/docker-curriculum/flask-app$ 

我已經採取了看看這個stackoverflow solution。這些答案似乎已經解決了許多人無法與域名服務器(DNS)連接的問題,但重置碼頭或添加DNS到/etc/dhcp/dhclient.conf沒有爲我做任何事情。

我已經安裝了Docker版本17.09.0-ce並且在Ubuntu 16.04上運行,有什麼想法?

+0

@JanezKuhar這似乎不是問題,因爲我正在拉一個'用戶圖像',它就像克隆某人的存儲庫。我也嘗試了你的解決方案,這導致了相同的結果 – Max

+0

錯誤信息表明嘗試訪​​問https://pypi.python.org/pypi時出現連接錯誤。您正在構建圖像的機器是否可以連接到該網站? – jwodder

+0

不,我不能。本質上問題是我無法連接到服務器,因爲我的機器找不到正確的DNS。但在SO解決方案中嘗試解決方案後,我仍然無法連接 – Max

回答

1

如果您正在使用代理服務器。碼頭集裝箱根本無法到達互聯網的可能性很大。

您可以通過運行

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

如果它掛你知道你有一個問題進行測試。現在我們必須找到主機用來連接互聯網的網絡接口。 ipconfig會給你一個名字列表,無論哪一個用來連接互聯網都是你的IFACENAME。現在運行:

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

這將列出您的代理服務器所在的IP_ADDRESS。可能有1個以上,只是使用第一個。使用以下內容創建文件/etc/docker/daemon.json

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

最後,

$ sudo service docker restart 

現在,您應該能夠從一個容器內ping通。