27

If I want to build my Dockerfile, it can't connect to the network or at least DNS:

Sending build context to Docker daemon 15.95 MB
Sending build context to Docker daemon 
Step 0 : FROM ruby
 ---> eeb85dfaa855
Step 1 : RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
 ---> Running in ec8cbd41bcff
W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie/InRelease  

W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie-updates/InRelease  

W: Failed to fetch http://security.debian.org/dists/jessie/updates/InRelease  

W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie/Release.gpg  Could not resolve 'httpredir.debian.org'

W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie-updates/Release.gpg  Could not resolve 'httpredir.debian.org'

W: Failed to fetch http://security.debian.org/dists/jessie/updates/Release.gpg  Could not resolve 'security.debian.org'

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 build-essential
INFO[0001] The command "/bin/sh -c apt-get update -qq && apt-get install -y build-essential libpq-dev" returned a non-zero code: 100

But if I run exactly the same command via docker run it works:

docker run --name="test" ruby /bin/sh -c 'apt-get update -qq && apt-get install -y build-essential libpq-dev'

Does anybody have an idea, why docker build does not work? I have tried all DNS related tipps on StackOverflow, like starting docker with --dns 8.8.8.8 etc.

Thanks in advance

sweiler
  • 397
  • 1
  • 3
  • 7

8 Answers8

33

Check what networks are available on your host with the below command:

docker network ls

then pick one that you know is working, the host one could be a good candidate.

Now assuming you are in the directory where it is available your Dokerfile, build your image appending the flag --networks and change the <image-name> with yours:

docker build . -t <image-name> --no-cache --network=host
Raffa
  • 376
  • 3
  • 5
13

Docker definitely seems to have some network issues. I managed to fix this problem with

systemctl restart docker

... which is basically just the unix-level 'restart-the-daemon' command in Debian 8.

John Clements
  • 16,895
  • 3
  • 37
  • 52
7

I had similar problem. But as I was running AWS linux i had no systemctl. I solved using:

sudo service docker restart
fegoulart
  • 1,706
  • 2
  • 12
  • 9
2

My docker build also failed while trying to run apt-get upgrade with the exact same errors. I was using docker-machine on Mac OSX and a simple docker-machine restart default solved this issue. No idea what initially caused this, though.

Jay V
  • 183
  • 1
  • 8
2

Another case of the above reported behaviour - this time building a docker image from Jenkins:

[...] Step 3 : RUN apt-get update && apt-get install -y curl libapache2-mod-proxy-html ---> Running in ea7aca5dea9b

Err http://security.debian.org jessie/updates InRelease

Err http://security.debian.org jessie/updates Release.gpg

Could not resolve 'security.debian.org' Err http://httpredir.debian.org jessie InRelease [...]

In my case it turned out that the DNS wasn't reachable from within the container - but still from the docker host !? (The containers resolver configuration was okay(!)) After restarting the docker machine (a complete reboot - a 'docker.service restart' didn't do the trick) it's been working again. So one of my activities (or of a colleague of mine) must have broken the docker networking then !?? Maybe some firewalld modification activity ???

I'm still investigating as I'm not sure which activity may have corrupted the docker networking then ...

Juergen Klasen
  • 829
  • 7
  • 11
0

I have the exact same issue with a Raspberry.

Start/stopping the service did not help, but re-installing the package (dpkg -i docker-hypriot_1.10.3-1_armhf.deb && service docker start in my case) immediately solved the situation : apt-get update manages to resolve and reach the servers.

There must be some one-shot actions in the installation process...

olivm
  • 106
  • 5
0

Also faced the same issue today. My workaround was to restart your docker-machine. In my case, it's on VirtualBox.

Once you power off it and then restart the machine, http://security.debian.org seemed resolved.

Hope this helps.

Tien Lin
  • 1,338
  • 1
  • 11
  • 6
-1

A couple of suggestions, not sure if they will work or not. Can you change the ...apt-get install -y... to ...apt-get install -yqq...

Also, has that image changed that you're trying to build from?

Hatem Jaber
  • 2,341
  • 2
  • 22
  • 38
  • The -yqq has not solved the issue. Also it fails on the apt-get update and does not even reach the apt-get install. The image could have changed, but since the `docker run` with exactly the same base image works, I don't think, that the problem is related to the image. – sweiler Aug 01 '15 at 16:33