21

I found some weird issue when trying to build my docker image in my house, although I am not sure if it's correlated to browser or just a network issue.

So here's what I got. I tried to run this command in my Dockerfile.

RUN apt-get update -qq && \
    apt-get install -y build-essential \
        libpq-dev \
        postgresql-client

After waiting for a moment, somewhat the process output something like this.

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

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

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

W: Failed to fetch http://deb.debian.org/debian/dists/jessie/Release.gpg  Temporary failure resolving 'deb.debian.org'

W: Failed to fetch http://security.debian.org/dists/jessie/updates/Release.gpg  Temporary failure resolving 'security.debian.org'

W: Failed to fetch http://deb.debian.org/debian/dists/jessie-updates/Release.gpg  Temporary failure resolving 'deb.debian.org'

W: Some index files failed to download. They have been ignored, or old ones used instead.

The weird thing is that, if I tried this in my office network, this does not happen. And then if I tried tethering to my cellphone data network, this also does not happen.

I tried opening http://deb.debian.org/debian/dists/jessie/InRelease in browser, it shows 404. I tried using Tor browser via several networks, it also shows 404.

The docker image is based on ruby:2.3.1.

UPDATE

I tried to use the DNS provided by my house provider 203.142.82.222.

sudo docker run --dns 203.142.82.222 busybox nslookup google.com

This resolves

Server:    203.142.82.222
Address 1: 203.142.82.222 dns-cache1.biz.net.id

Name:      google.com
Address 1: 2404:6800:4003:808::200e sin10s07-in-x0e.1e100.net
Address 2: 117.102.117.245
Address 3: 117.102.117.251
Address 4: 117.102.117.212

But then I changed to /etc/default/docker file and added this.

DOCKER_OPTS="--dns 203.142.82.222 --dns 203.142.84.222"

After I restarted the docker sudo service docker restart, I tried again but it's still not working.

sudo service docker restart
sudo docker run busybox nslookup google.com
Server:    8.8.8.8
Address 1: 8.8.8.8

nslookup: can't resolve 'google.com'
Petra Barus
  • 3,815
  • 8
  • 48
  • 87

4 Answers4

12

I just dealt with this issue building the cartoza/postgis image, that stems from debian:stable. This happens because some popular public DNS are not reachable from this network, e.g.:

$ nslookup duckduckgo.com 8.8.8.8
;; connection timed out; no servers could be reached

Possibly the simplest way around this is to directly instruct Docker to use the DNS available to the network. Start by verifying their addresses:

$ nmcli dev show | grep 'IP4.DNS'
IP4.DNS[1]:                             10.91.3.31
IP4.DNS[2]:                             10.90.3.31
IP4.DNS[3]:                             10.90.7.14

Add them to a new configuration file called daemon.json:

$ sudo pico /etc/docker/daemon.json

And insert the following:

{
    "dns": ["10.91.3.31", "10.90.3.31", "10.90.7.14"]
}

Then restart the service:

$ sudo service docker restart
Luís de Sousa
  • 5,765
  • 11
  • 49
  • 86
  • 1
    Luis, can you explain further what is missing on docker to detect or use the DNS available? Like, there isn't a docker service to discover and fill the docker/daemon.json automatically? – Felipe Bormann Oct 17 '19 at 19:15
4

One reason could be that your proxy is not set in Docker file, add these 2 lines in Dockerfile:

ENV http_proxy "http://www-proxy.x.com:80"
ENV https_proxy "http://www-proxy.x.com:80"

Please, update your proxy there. And don't write

ENV HTTP_PROXY "http://www-proxy.x.com:80"

because the env variable is the case sensitive

Vicky Gupta
  • 576
  • 6
  • 13
3

The /etc/default/docker file is only used on systems using "upstart" and "SysVInit", not on systems using systemd.

This is also mentioned at the top of the file: https://github.com/docker/docker/blob/44fe8cbbd174b5d85d4a063ed270f6b9d2279b70/contrib/init/sysvinit-debian/docker.default#L1

So, don't use /etc/default/docker. It's used only by upstart, which is not used by Ubuntu since 16.04.

Use /etc/docker/daemon.json, which is documented here: https://docs.docker.com/engine/reference/commandline/dockerd/#/linux-configuration-file

There you can configure your dns

Robert
  • 33,429
  • 8
  • 90
  • 94
0

Adding

ENV http_proxy "http://www-proxy.x.com:80"
ENV https_proxy "http://www-proxy.x.com:80"

at the end of my Docker file worked for me.

Martín Mori
  • 1,021
  • 1
  • 7
  • 5