问题:任何使用依赖于 centos、ubuntu 或 debian 的 Dockerfile 的构建都无法构建.
PROBLEM: Any build, with a Dockerfile depending on centos, ubuntu or debian fails to build.
环境:我有一个 Mac OS X,运行 VMWare 和一个来宾 Ubuntu 14.04,运行 Docker:
ENVIRONMENT: I have a Mac OS X, running VMWare with a guest Ubuntu 14.04, running Docker:
mdesales@ubuntu ~ $ sudo docker version Client version: 1.1.2 Client API version: 1.13 Go version (client): go1.2.1 Git commit (client): d84a070 Server version: 1.1.2 Server API version: 1.13 Go version (server): go1.2.1 Git commit (server): d84a070行为:使用docker build"无法下载包.以下是此类 Dockerfile 的示例:github/Krijger/docker-cookbooks/blob/master/jdk8-oracle/Dockerfile, github/ottenhoff/centos-java/blob/master/Dockerfile
BEHAVIOR: Using "docker build" fails to download packages. Here's an example of such Dockerfile: github/Krijger/docker-cookbooks/blob/master/jdk8-oracle/Dockerfile, github/ottenhoff/centos-java/blob/master/Dockerfile
我知道我们可以使用 --dns 运行容器,但这是在构建期间.
I know that we can run a container with --dns, but this is during the build time.
CENTOS
CENTOS
来自 centos运行 yum install a b c
FROM centos RUN yum install a b c
UBUNTU
来自 ubuntu运行 apt-get install a b c
FROM ubuntu RUN apt-get install a b c
用户报告可能是 DNS 配置问题,其他配置有 Google 的 DNS 服务器注释掉.
Users have reported that it might be problems with DNS configuration, others and the configuration has the Google's DNS servers commented out.
Step 2 : RUN yum install -y curl; yum upgrade -y; yum update -y; yum clean all ---> Running in 5f11b65c87b8 Loaded plugins: fastestmirror Couldn't resolve host 'mirrorlist.centos问题仍然存在......所以,#docker@Freenode 上的大多数用户都提到这可能是 DNS 配置的问题......所以这是我的 Ubuntu:
Still the problem persisted... So, most users on #docker@Freenode mentioned that it might be a problem with the DNS configuration... So here's my Ubuntu:
$ sudo cat /etc/resolv.conf nameserver 127.0.1.1 search localdomain我尝试改变它,同样的问题......
I tried changing that, same problem...
推荐答案问题
在#docker@freenode 与一些开发人员交谈时,每个人都清楚问题所在:DNS 和环境.该构建在家里的常规 Internet 连接上运行良好.
Talking to some developers at #docker@freenode, the problem was clear to everyone: DNS and the environment. The build works just fine at a regular Internet connection at home.
解决方案:
此问题发生在具有私有 DNS 服务器的环境中,或者网络阻止了 Google 的 DNS 服务器.即使 docker 容器可以 ping 8.8.8.8,构建仍然需要访问防火墙或数据中心后面的同一个私有 DNS 服务器.
This problem occurs in an environment that has a private DNS server, or the network blocks the Google's DNS servers. Even if the docker container can ping 8.8.8.8, the build still needs to have access to the same private DNS server behind your firewall or Data Center.
使用 --dns 开关启动 Docker 守护程序以指向您的私有 DNS 服务器,就像配置您的主机操作系统一样.这是通过反复试验发现的.
Start the Docker daemon with the --dns switch to point to your private DNS server, just like your host OS is configured. That was found by trial and error.
详情
我的 MAC OS X 主机操作系统在我的/etc/resolv.conf 上配置了不同的 DNS:
My MAC OS X, host OS, had a different DNS configured on my /etc/resolv.conf:
mdesales@Marcello-Work ~ (mac) $ cat /etc/resolv.conf search corp.my-private-company nameserver 172.18.20.13 nameserver 172.20.100.29我的主机可能在构建时将数据包丢弃到 Google 的 IP 地址 8.8.8.8...我只是将这 2 个 IP 地址放在 Ubuntu 的 docker daemon 配置下:
My host might be dropping the packets to the Google's IP address 8.8.8.8 while building... I just took those 2 IP addresses and placed under the Ubuntu's docker daemon configuration:
mdesales@ubuntu ~ $ cat /etc/default/docker ... ... # Use DOCKER_OPTS to modify the daemon startup options. DOCKER_OPTS="--dns 172.18.20.13 --dns 172.20.100.29 --dns 8.8.8.8" ...构建现在按预期工作!
$ sudo ./build.sh Sending build context to Docker daemon 7.168 kB Sending build context to Docker daemon Step 0 : FROM centos ---> b157b77b1a65 Step 1 : MAINTAINER Marcello_deSales@intuit ---> Running in 49bc6e233e4c ---> 2a380810ffda Removing intermediate container 49bc6e233e4c Step 2 : RUN yum install -y curl; yum upgrade -y; yum update -y; yum clean all ---> Running in 5f11b65c87b8 Loaded plugins: fastestmirror Determining fastest mirrors * base: mirror.supremebytes * extras: centos.mirror.ndchost * updates: mirrors.tummy Resolving Dependencies --> Running transaction check ---> Package systemd.x86_64 0:208-11.el7 will be updated ---> Package systemd.x86_64 0:208-11.el7_0.2 will be an update ---> Package systemd-libs.x86_64 0:208-11.el7 will be updated ---> Package systemd-libs.x86_64 0:208-11.el7_0.2 will be an update --> Finished Dependency Resolution感谢@BrianF 和其他在 IRC 频道中提供帮助的人!
Thanks to @BrianF and others who helped in the IRC channel!
永久虚拟机解决方案 - 2015 年 7 月 2 日更新
我们现在混合使用了 GitHub Enterprise 和 CoreOS Enterprise Docker Registry……因此,从 HOST 机器添加公司 DNS 服务器以使 VM 也能正常工作对我来说很重要.
We now have GitHub Enterprise and CoreOS Enterprise Docker Registry in the mix... So, it was important for me to add the corporate DNS servers from the HOST machine in order to get the VM also to work.
用主机的/etc/resolv.conf 替换来宾操作系统的/etc/resolv.conf 也解决了这个问题!码头工人 1.7.0.我刚刚在 VMWare Fusion 上使用 Ubuntu 15.04 创建了一个新 VM,但我又遇到了这个问题...
Replacing the /etc/resolv.conf from the guest OS with the Host's /etc/resolv.conf also resolved the problem! Docker 1.7.0. I just created a new VM using Ubuntu 15.04 on VMWare Fusion and I had this problem again...
/etc/resolv.conf 之前
~/dev/github/public/stackedit on ⭠ master ⌚ 20:31:02 $ cat /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 127.0.1.1 search localdomain/etc/resolv.conf 之后*
~/dev/github/public/stackedit on ⭠ master ⌚ 20:56:09 $ cat /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN search corp.mycompany nameserver 10.180.194.35 nameserver 10.180.194.36 nameserver 192.168.1.1更多推荐
Dockerfile: Docker build 无法下载包:centos
发布评论