Dockerfile: Docker build can't download packag

2019-01-16 14:30发布

PROBLEM: Any build, with a Dockerfile depending on centos, ubuntu or debian fails to build.

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

BEHAVIOR: Using "docker build" fails to download packages. Here's an example of such Dockerfile: https://github.com/Krijger/docker-cookbooks/blob/master/jdk8-oracle/Dockerfile, https://github.com/ottenhoff/centos-java/blob/master/Dockerfile

I know that we can run a container with --dns, but this is during the build time.

  • CENTOS

    FROM centos RUN yum install a b c

  • UBUNTU

    FROM ubuntu RUN apt-get install a b c

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.org

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...

7条回答
时光不老,我们不散
2楼-- · 2019-01-16 15:13

For me the problem was that my ISP blocked google's DNS (8.8.8.8) which docker uses as a fallback default.

The trick here is to find out your DNS IP and tell docker to use it.

In my case (running Ubuntu 17.04), trying to get this information from /etc/resolv.conf did not work, but I used this command:

nmcli dev show | grep IP4.DNS

Then I took this IP and added in /etc/defaults/docker:

DOCKER_OPTS="--dns 192.168.50.1"

Now restart your docker daemon, and try building again.

查看更多
登录 后发表回答