Docker DNS problem

If you are having difficulty installing docker on CentOS 8, read this article.

There was a need to build an image with the installation of dependencies for python. Dependencies are described in the requirements.txt file and must be pulled from the network. However, when building the image I received an error of the following form:

Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fd0844380f0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)'

This error indicates that docker cannot resolve the domain name to establish a connection to the remote server. After checking in busybox (if the image is not in your local repository, docker will automatically download it), we see that the dns really does not work:

# docker run busybox nslookup google.com
;; connection timed out; no servers could be reached

Docker DNS Problem – Bug Fix

In order for docker to no longer have a problem with dns, you need to specify the dns server in the docker settings. To do this, open the docker configuration file:

# nano /etc/docker/daemon.json

If the file does not exist yet, the editor will automatically create it.

Now indicate the dns server, for example from google:

{
    "dns": ["8.8.8.8"]
}

And restart docker:

# systemctl restart docker

Check and make sure that everything works:

# docker run busybox nslookup google.com
Server:         8.8.8.8
Address:        8.8.8.8:53

Non-authoritative answer:
Name:   google.com
Address: 64.233.163.113
Name:   google.com
Address: 64.233.163.101
Name:   google.com
Address: 64.233.163.102
Name:   google.com
Address: 64.233.163.139
Name:   google.com
Address: 64.233.163.100
Name:   google.com
Address: 64.233.163.138

Leave a Comment