2015-12-07 54 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