【问题标题】:docker build failing with Could not resolve 'archive.ubuntu.com'docker build 失败,无法解析“archive.ubuntu.com”
【发布时间】:2015-12-07 19:19:25
【问题描述】:

我无法使用以下 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 上运行

谢谢!

【问题讨论】:

标签: ubuntu docker boot2docker


【解决方案1】:

这个问题已经回答了 Docker build "Could not resolve 'archive.ubuntu.com'" apt-get fails to install anything

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

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

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

更新: 从下面的 cmets 中:当您在网络之间移动时,例如在 wifi 网络之间或在家庭和工作之间,容器不知道它在新网络中。重新启动 VM 或 Docker 机器是最好的解决方法。

【讨论】:

  • 重启 VirtualBox VM 解决了我在运行 Docker Toolbox 的 Mac 上的这个问题。
  • 我的猜测是当我们在网络之间移动并且容器已经在运行时,它无法获取新的网络设置。当您的主机在虚拟机启动后位于不同的网络上时,我不确定 VirtualBox 如何处理这种情况。
  • @ed209 你应该把它作为一个单独的答案发布;)对我也有用!
【解决方案2】:

在我的 Ubuntu 主机上,/etc/default/docker 中的以下条目

DOCKER_OPTS="--dns 172.21.32.182"

然后:

sudo systemctl daemon-reload
sudo systemctl restart docker

帮助解决了网络连接问题。当然你需要用你的 dns 替换 172.21.32.182。

【讨论】:

  • 对我来说只有最后两行运行良好,解决了我所有的问题!
【解决方案3】:

https://github.com/boot2docker/boot2docker/issues/451#issuecomment-65432123。可能发生的情况是您的 VirtualBox NAT DNS 代理有一条陈旧的路由。您通常必须重新启动 VM 才能使其再次工作。

另一种解决方法是让 VM 使用您的主机解析器(应在 DHCP 分发新名称服务器时更新)。假设您的机器在 Docker Machine 下被命名为 dev,您可以执行以下操作:

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

【讨论】:

  • 是的,这适用于 OSX 10.9,docker-machine docker-machine version 0.5.4,docker 1.9.1;非常感谢
【解决方案4】:

Docker 构建因警告而失败 ---> [Warning] IPv4 forwarding is disabled. Networking will not work 即使您可以解决archive.ubuntu.com 解决方案-

  • 防火墙开启。
  • 在我的情况下为centos7-将以下内容添加到 /etc/sysctl.conf: net.ipv4.ip_forward = 1
  • 应用 sysctl 设置: sysctl -p

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 2021-03-06
    • 1970-01-01
    • 2019-03-16
    • 1970-01-01
    相关资源
    最近更新 更多