Reputation: 547
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
Upvotes: 42
Views: 29552
Reputation: 949
For those using Docker compose:
services:
web:
build:
context: .
dockerfile: ./Dockerfile
# the line below fixes the network access
network: host
Upvotes: 4
Reputation: 496
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
Upvotes: 45
Reputation: 1508
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.
Upvotes: 0
Reputation: 2037
I had similar problem. But as I was running AWS linux i had no systemctl. I solved using:
sudo service docker restart
Upvotes: 7
Reputation: 829
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 ...
Upvotes: 2
Reputation: 17203
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.
Upvotes: 22
Reputation: 106
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...
Upvotes: 0
Reputation: 183
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.
Upvotes: 2
Reputation: 2402
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?
Upvotes: -3