2015-12-07 92 views
2

我無法與以下Dockerfile打造自己的形象:搬運工構建與失敗無法解析「archive.ubuntu.com」

FROM ubuntu 

RUN apt-get -y update && apt-get -y install \ 
nodejs npm ssh 

# cache npm install when package.json hasn't changed 
WORKDIR /tmp 
ADD package.json package.json 
RUN npm install 
RUN npm install -g pm2 

RUN mkdir /sparrow 
RUN cp -a /tmp/node_modules /sparrow 

WORKDIR /sparrow 
ADD . /sparrow/ 
RUN npm run build 

# ssh keys 
WORKDIR /root 
RUN mv /sparrow/.ssh /root/ 

# upload js and css 
WORKDIR /sparrow/build 
# UPLOAD TO S3! 

# go back to /sparrow 
WORKDIR /sparrow 

ENV NODE_ENV production 
ENV NODE_PATH "./src" 

EXPOSE 8000 
CMD ["pm2", "start", "./bin/server.js", "--no-daemon", "-i", "0"] 

好像它有連接到互聯網,安裝Ubuntu的軟件包,並與失敗的煩惱:

Err http://archive.ubuntu.com trusty InRelease 

Err http://archive.ubuntu.com trusty-updates InRelease 

Err http://archive.ubuntu.com trusty-security InRelease 

Err http://archive.ubuntu.com trusty Release.gpg 
    Could not resolve 'archive.ubuntu.com' 
Err http://archive.ubuntu.com trusty-updates Release.gpg 
    Could not resolve 'archive.ubuntu.com' 
Err http://archive.ubuntu.com trusty-security Release.gpg 
    Could not resolve 'archive.ubuntu.com' 
Reading package lists... 
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/InRelease 

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/InRelease 

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/InRelease 

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg Could not resolve 'archive.ubuntu.com' 

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg Could not resolve 'archive.ubuntu.com' 

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg Could not resolve 'archive.ubuntu.com' 

W: Some index files failed to download. They have been ignored, or old ones used instead. 
Reading package lists... 
Building dependency tree... 
Reading state information... 
E: Unable to locate package nodejs 
E: Unable to locate package npm 

有關如何解決或測試此問題的任何建議?在El Capitan OSX上運行

謝謝!

+1

的可能的複製[泊塢建設「無法解析'archive.ubuntu.com'」apt-get無法安裝任何東西](http:// stackoverflow。COM /問題/ 24991136 /泊塢窗 - 構建 - 能 - 不解決,歸檔的ubuntu-COM-apt-get的-無法安裝的-A) –

回答

7

這在 Docker build "Could not resolve 'archive.ubuntu.com'" apt-get fails to install anything

已回答這也影響百勝等回購經理,因爲我們希望他們可以訪問,但集裝箱已使主機

我只喜歡網絡設置

#DNS update: This is needed to run yum and to let the docker build process access the internet. 
RUN "sh" "-c" "echo nameserver 8.8.8.8 >> /etc/resolv.conf" 

更新: 從下面的意見:在我的腳本開始添加這些線WH如果你在網絡之間移動,說wifi網絡之間或家庭與工作之間的容器不知道它在一個新的網絡。重新啓動VM或Docker機器是最好的解決方案。

+2

重啓VM VirtualBox的固定在我的Mac這個問題上運行的泊塢窗工具箱。 – ed209

+0

我的猜測是當我們在網絡之間移動並且容器已經運行時,它不能接收新的網絡設置。我不確定VirtualBox如何處理這種情況,當您的主機在VM啓動後在不同的網絡上。 – SidJ

+0

@ ed209你應該把它作爲一個單獨的答案發布;)對我來說也有訣竅! – jessepinho

1

參見https://github.com/boot2docker/boot2docker/issues/451#issuecomment-65432123。可能發生的情況是您的VirtualBox NAT DNS代理具有陳舊的路由。您通常必須重新啓動虛擬機才能再次運行。

另一個解決方法是讓虛擬機使用您的主機解析器(當DHCP實施新的名稱服務器時應更新它)。假設你的機器下泊塢窗機命名爲dev,你可以這樣做:

docker-machine stop dev 
VBoxManage modifyvm dev --natdnsproxy1 off --natdnshostresolver1 off 
docker-machine start dev 
+0

Yesss,這適用於OSX 10.9,碼頭機碼頭機版本0.5.4,碼頭1.9.1;非常感謝你 – ocramz

3

在Ubuntu主機我在/ etc /默認以下條目/泊塢窗

DOCKER_OPTS="--dns 172.21.32.182" 

,然後:

sudo systemctl daemon-reload 
sudo systemctl restart docker 

有助於解決網絡連接問題。當然你需要用你的dns替換172.21.32.182。

+1

對我來說,只有最後兩行工作正常,並解決了我所有的問題! –

+0

最後兩行做到了! –

0

泊塢構建失敗,因爲警告 ---> [Warning] IPv4 forwarding is disabled. Networking will not work ,即使你可以在防火牆上解決archive.ubuntu.com 解決方案 -

  • 在我的情況下centos7-添加到 /etc/sysctl.conf中:把net.ipv4.ip_forward = 1
  • 應用sysctl設置: 的sysctl -p