Network calls fail during image build on corporate network

For any Linux distribution working with SystemD (Ubuntu 16, RHEL 7...), the path will be displayed with the following command:

$ systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2016-06-29 08:10:33 PDT; 2min 34s ago
 Main PID: 1169 (dockerd)
    Tasks: 19
   Memory: 85.0M
      CPU: 1.779s
   CGroup: /system.slice/docker.service
           ├─1169 /usr/bin/dockerd --dns --dns --dns --dns -H fd://
           └─1232 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --shim docker-containerd-shim --met

The path would be /lib/systemd/system/docker.service. Add the DOCKER_OPTS values, which can have any of the --dns, in the line where the daemon is started.

cat /lib/systemd/system/docker.service | grep dns 
ExecStart=/usr/bin/dockerd --dns --dns --dns --dns  -H fd://

I advise changing the DNS settings of the Docker daemon. You can set the default options for the docker daemon by creating a daemon configuration file at /etc/docker/daemon.json. Set DNS server according to your host machine, e.g. my DNS server is

{"dns": ["", ""] }

Then you need just restart docker service:

sudo service docker restart

Step-by-step explanation is available here Fix Docker's networking DNS config

The following steps works for me ( for both docker build and docker run command). My linux version is Ubuntu 14.04.

  • Identify DNS using following command.
    nm-tool | grep DNS

This result DNS: in my case

  • Create entry in /etc/default/ My current entry looks like this
DOCKER_OPTS="--dns --dns --dns"
  • Restart docker service
 sudo service restart 

I was able to figure out the issue. On Ubuntu, Docker sets the DNS servers for container to Google's servers at 8.8.8.x. As I understand it, this is a workaround on Ubuntu due to the fact that Ubuntu sets /etc/resolv.conf to be

Those Google servers weren't accessible from behind our firewall, which is why we couldn't resolve any URLs.

The fix is to tell Docker which DNS servers to use. This fix depends on how you installed Docker:

Ubuntu Package

If you have the Ubuntu package installed, edit /etc/default/docker and add the following line:

DOCKER_OPTS="--dns <your_dns_server_1> --dns <your_dns_server_2>"

You can add as many DNS servers as you want to this config. Once you've edited this file you'll want to restart your Docker service:

sudo service docker restart


If you've installed Docker via the binaries method (i.e. no package), then you set the DNS servers when you start the Docker daemon:

sudo docker -d -D --dns <your_dns_server_1> --dns <your_dns_server_2> &