ubuntu - docker 构建失败,无法解析 'archive.ubuntu.com'

标签 ubuntu docker boot2docker

我无法使用以下 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"]

似乎无法连接到 Internet 以安装 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 上运行

谢谢!

最佳答案

这个问题已经在 <强> 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"

更新: 来自下面的评论:当你在网络之间移动时,比如在 wifi 网络之间或在家庭和工作之间,容器不知道它在一个新网络中。重启 VM 或 Docker 机器是最好的解决方法。

关于ubuntu - docker 构建失败,无法解析 'archive.ubuntu.com',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34141438/

相关文章:

ubuntu - Linux 上的 WebView

apache - 如何在 Ubuntu 上同时运行 nginx 和 Apache?

linux - 多个 docker 容器、IP 地址、VM、OSX

docker - 与docker exec等效的boot2docker

bash - 为什么在没有为测试提供任何参数时,在 bash 中使用 -f 进行测试会返回 true?

linux - 你如何修复 "Build failed: Android SDK dir was not specified, exiting."

docker - 如何在Docker sh入口点修复 'Permission denied'

windows - Windows 2016 上的 Docker 错误 "Client.Timeout exceeded while awaiting headers"

docker - 如何在docker中使用traefik代理后端

docker - docker容器中的mysql无法通过os x上的挂载卷运行