Docker build has no network, but docker run has
Asked Answered
R

9

40

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

Rabbi answered 1/8, 2015 at 15:49 Comment(1)
I should mention, that exactly the same Dockerfile has worked some weeks ago.Rabbi
F
43

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
Fabiolafabiolas answered 23/8, 2021 at 9:48 Comment(0)
D
18

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.

Disquietude answered 23/6, 2016 at 23:50 Comment(2)
This fix my problem, I have docker 1.12.0, I think that is problem operating system or what can it be?Doane
This fixed my issue, thanks! (Ubuntu 20.04 host)Bassoon
A
7

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

sudo service docker restart
Adar answered 26/9, 2016 at 2:53 Comment(0)
H
4

For those using Docker compose:

services:
    web:
        build:
            context: .
            dockerfile: ./Dockerfile
            # the line below fixes the network access
            network: host
Helli answered 22/4 at 21:51 Comment(0)
A
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.

Accounting answered 27/4, 2016 at 13:12 Comment(0)
I
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 ...

Inducement answered 28/6, 2016 at 6:15 Comment(0)
C
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...

Contreras answered 28/5, 2016 at 17:16 Comment(0)
B
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.

Bloke answered 26/4, 2017 at 10:20 Comment(0)
F
-2

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?

Florentinoflorenza answered 1/8, 2015 at 16:17 Comment(1)
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.Rabbi

© 2022 - 2024 — McMap. All rights reserved.