当前位置:  开发笔记 > 编程语言 > 正文

docker build失败,无法解析'archive.ubuntu.com'

如何解决《dockerbuild失败,无法解析'archive.ubuntu.com'》经验,为你挑选了1个好方法。

我无法使用以下Dockerfile构建我的图像:

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> SidJ..:

Docker build"无法解析'archive.ubuntu.com'"已经 解决了这个问题."apt-get无法安装任何东西

这也会影响yum和其他repo manger,因为我们希望它们可以访问,但容器只有主机允许的网络设置

我想在脚本的开头添加这些行:

#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"

更新:从下面的评论:当您在网络之间移动时说在无线网络之间或在家庭和工作之间,容器不知道它在新网络中.重启VM或Docker机器是最好的解决方案.


Rebooting the VirtualBox VM fixed this issue on my Mac running Docker Toolbox.
推荐阅读
贾志军
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有