Bobcares

Docker image DNS lookup error: How to resolve

by | Nov 17, 2021

Stuck with a Docker image DNS lookup error? Fear not, our Support Team is here with a solution.

At Bobcares, coming up with solutions for queries, big and small is a part of our Server Management Services.

Let’s take a look at how our Support Team resolved the DNS lookup error today.

About DNS lookup errors

Have you been experiencing a number of obscure errors with your applications?? This might be due to Docker’s internet connectivity issues. According to our Support Tech, this may be a result of failing DNS lookups. Resolving this issue will also help you bid adieu to the pesky docker image DNS lookup error.

Narrowing down docker image DNS lookup error

First, we will check the basic internet connectivity by pinging a public IP address. If it succeeds, you will get a similar output as seen below:

$ docker run busybox ping -c 1 192.203.230.10 # Ping a London-based NASA root nameserver PING 192.203.230.10 (192.203.230.10): 56 data bytes 64 bytes from 192.203.230.10: seq=0 ttl=53 time=113.866 ms --- 192.203.230.10 ping statistics --- 1 packets transmitted, 1 packets received, 0% packet loss round-trip min/avg/max = 113.866/113.866/113.866 ms

After that, let’s try resolving google.com domain as shown below:

$ docker run busybox nslookup google.com 
Server: 8.8.8.8 
Address 1: 8.8.8.8 nslookup: can't resolve 'google.com'

If you get a “can’t resolve” message as seen above, it indicates a problem with resolving DNS.

Why does docker image DNS lookup error occur?

Before we dive into resolving the issue, let’s take a look at why the DNS lookup errors keep occurring. In fact, a DNS server that is locally defined in the /etc/resolv.conf file, containers by default, use 8.8.8.8, Google’s public DNS server to resolve DNS.

Hence, the error occurs, then this process is interrupted. Interestingly, in some places, network administrators intentionally block public DNS servers to ensure that the network’s own DNS server is used instead.

In such cases, Docker containers that rely on the default configuration are unable to resolve DNS. Thereby making the internet unusable from within those containers.

Quick fix for docker image DNS lookup error

Our Support Engineers have come up with a quick fix to ensure that the docker container runs with a custom DNS server.

  1. First, we will track down the address of the DNS server from within Ubuntu with the following command:
    $ nmcli dev show | grep 'IP4.DNS' 
    IP4.DNS[1]:                       10.0.0.2
  2. Then, we will run a docker container with the DNS server obtained in the previous step. We will include the –dns flag as well with the command as seen below:
    $ docker run --dns 10.0.0.2 busybox nslookup google.com 
    Server: 10.0.0.2 
    Address 1: 10.0.0.2 
    Name: google.com 
    Address 1: 2a00:1450:4008:811::200e lhr26s02-in-x200e.1e100.net 
    Address 2: 216.58.198.173 lhr25s10-in-f14.1e100.net

Permanent fix for docker image DNS lookup error

If you prefer a more permanent fix, our Support Engineers have that covered as well.

  1. First, we will change the DNS settings of the Docker daemon by creating the daemon configuration file at /etc/docker/daemon.json.
  2. Then, configure the daemon configuration file with a set of two DNS, namely, the network DNS server and the Google DNS server. The latter works as a backup in case the network DNS server is not available.
    /etc/docker/daemon.json:
    {
        "dns": ["10.0.0.2", "8.8.8.8"]
    }
  3. After that, restart the docker service with the following command:
    sudo service docker restart

You can test this fix by pinging google.com from any Docker container without having to override the DNS server. For instance:

$ docker run busybox nslookup google.com 
Server: 10.0.0.2 
Address 1: 10.0.0.2 
Name: google.com 
Address 1: 2a00:1450:4008:811::200e lhr26s02-in-x200e.1e100.net 
Address 2: 216.58.198.173 lhr25s10-in-f13.1e100.net

[Need a hand with another query? Give us a call today.]

Conclusion

At the end of the day, we learned how to resolve the DNS lookup error. The Support Team at Bobcares offered us a quick fix as well as a more permanent fix to resolve the issue.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.