这是一个老问题了,但确实没找到原因。
Dockerfile 内容:
FROM ubuntu:xenial
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y net-tools
CMD ifconfig
build 时报错:
Step 1/4 : FROM ubuntu:xenial
---> 13c9f1285025
Step 2/4 : RUN apt-get update && apt-get upgrade -y
---> Running in 7d9b2ce81413
Err:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
Temporary failure resolving 'security.ubuntu.com'
Err:2 http://archive.ubuntu.com/ubuntu xenial InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease
Temporary failure resolving 'archive.ubuntu.com'
Reading package lists...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-backports/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease Temporary failure resolving 'security.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...
Calculating upgrade...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
---> 2bbbf2281fbf
Removing intermediate container 7d9b2ce81413
Step 3/4 : RUN apt-get install -y net-tools
---> Running in ce96aba3aea8
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package net-tools
The command '/bin/sh -c apt-get install -y net-tools' returned a non-zero code: 100
很明显是 apt-get 无法 update
已经尝试的解决方式:
1、更改为国内源(阿里源与 163 源,也测试过 sed 直接修改),无效:
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
echo 'deb http://mirrors.163.com/debian/ jessie main non-free contrib' > /etc/apt/sources.list && \
echo 'deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib' >> /etc/apt/sources.list
报错原因同之前:
Err:1 http://mirrors.163.com/debian jessie InRelease
Temporary failure resolving 'mirrors.163.com'
2、尝试更改 DNS ( 1 )我需要在 docker build 时指定 DNS,不是 run 的时候 ( 2 ) DNS 中已经有 114.114.114.114
PS:宿主机可以执行 apt-update
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.