Need help?

Our experts have had an average response time of 12.14 minutes in September 2021 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

Docker 504 DNS lookup failed – How to fix it?

by | Oct 22, 2021

Most often, we come across Docker 504 DNS lookup failed due to an invalid DNS server.

As part of our Docker Hosting Services, we assist our customers with several Docker queries.

Today, let us see the methods we employ to resolve this issue.


Docker 504 DNS lookup failed

As soon as we face this issue, we need to run cat /etc/resolv.conf in the docker container.

If it has an invalid DNS server, the container will fail to resolve the domain names into IP addresses. Hence, ping fails.

Next, we need to check the cat /etc/resolv.conf on the host machine.

Every time a container starts Docker copies the host’s /etc/resolv.conf to the container. So if the host’s /etc/resolv.conf is wrong, then so will the docker container.

Suppose we find that the host’s /etc/resolv.conf is wrong, then we have 2 options.

Moving ahead, let us see how our Support Techs go about them.

1. Hardcode DNS server in docker daemon.json

Initially, we edit /etc/docker/daemon.json

"dns": ["", ""]

Then for the changes to take effect, we restart the docker daemon:

sudo systemctl restart docker

Eventually, when we run/start a container, docker will populate /etc/resolv.conf with the values from daemon.json.

2. Fix the host’s /etc/resolv.conf

Here, our Support Techs recommend two options. Let us discuss the same.

A. Ubuntu 16.04 and earlier

In this case, /etc/resolv.conf isas dynamically generated by NetworkManager.

We need to comment out the line dns=dnsmasq (with a #) in /etc/NetworkManager/NetworkManager.conf

Then we restart the NetworkManager to regenerate /etc/resolv.conf :

sudo systemctl restart network-manager

Finally, we verify on the host: cat /etc/resolv.conf

B. Ubuntu 18.04 and later

Ubuntu 18.04 uses systemd-resolved to generate /etc/resolv.conf. Now by default, it uses a local DNS cache

That will not work inside a container. In such a scenario, Docker defaults to Google’s DNS server, which may break for people behind a firewall.

/etc/resolv.conf is actually a symlink (ls -l /etc/resolv.conf) which points to /run/systemd/resolve/stub-resolv.conf ( by default.

We need to just change the symlink to point to /run/systemd/resolve/resolv.conf, which lists the real DNS servers:

sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

Then we verify on the host: cat /etc/resolv.conf

Now we will have a valid /etc/resolv.conf on the host for docker to copy into the containers.

[Need further assistance? We are glad to assist you]



In short, we saw how our Support Techs fix this issue for our customers.


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.



Submit a Comment

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



Privacy Preference Center


Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]


Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid


Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie


These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.