docker构建失败无法解析'archive.ubuntu.com' [英] docker build failing with Could not resolve 'archive.ubuntu.com'

查看:771
本文介绍了docker构建失败无法解析'archive.ubuntu.com'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 从ubuntu 

运行apt-获得更新&&& apt-get -y install \
nodejs npm ssh

#cache npm install当package.json没有更改
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
添加。 / sparrow /
运行npm运行build

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

#上传js和css
WORKDIR / sparrow / build
#上传到S3!

#返回/ 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
无法解析 archive.ubuntu.com'
Err http://archive.ubuntu.com trusty-updates Release.gpg
无法解析'archive.ubuntu.com'
Err http:// archive .ubuntu.com trusty-security Release.gpg
无法解析'archive.ubuntu.com'
读取包列表...
W:无法获取http://archive.ubuntu的.com / Ubuntu的/ dists中/可信任/ InReleas e

W:无法提取http://archive.ubuntu.com/ubuntu/dists/trusty-updates/InRelease

W:无法获取http:// archive.ubuntu.com/ubuntu/dists/trusty-security/InRelease

W:无法提取http://archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg无法解析'archive.ubuntu.com'

W:无法提取http://archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg无法解析'archive.ubuntu.com '

W:无法提取http://archive.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg无法解析'archive.ubuntu.com'

W:某些索引文件无法下载。他们被忽视了,或者旧的被使用了。
阅读包列表...
构建依赖关系树...
读取状态信息...
E:无法找到包nodejs
E:无法找到包npm

有关如何解决或测试此问题的任何建议?在El Capitan OSX上运行



谢谢!

解决方案


Docker构建无法解析archive.ubuntu.com apt-get无法安装任何内容



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



我喜欢在脚本开头添加这些行:

  #DNS更新:这是运行yum并让Docker构建进程访问互联网所必需的。 
RUNsh-cecho nameserver 8.8.8.8>> /etc/resolv.conf

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


I cannot build my image with the following 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"]

Seems like it's having trouble connecting to the internet to install ubuntu packages and failing with:

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

Any suggestions for how to resolve or test this problem? Running on El Capitan OSX

Thanks!

解决方案

This has been answered at Docker build "Could not resolve 'archive.ubuntu.com'" apt-get fails to install anything

This also affects yum and other repo mangers since we expect them to be accessible but the containers have only the network settings allowed in the host

I like to add these lines at the start of my scripts:

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

Update: From the comments below: when you move between networks say between wifi networks or between home and work the container doesn't know it's in a new network. Restarting the VM or Docker machine is the best fix.

这篇关于docker构建失败无法解析'archive.ubuntu.com'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆