Skip to main content

How To Fix Docker Container DNS / Internet Issues

·1 min

Your Docker containers don’t seem to have internet connection or can’t resolve DNS queries?

TLDR; This issue is most likely due to the fact that your containers can’t resolve DNS queries using your host’s DNS servers (which may be unreachable from the containers). You can fix this in two ways:

  • Globally for all Docker containers
  • Locally for an individual container

Fixing DNS Or Internet Issues Globally For All Docker Containers #

Edit the Docker daemon configuration file at /etc/docker/daemon.json or create it if it doesn’t exist. Then, add new custom DNS servers:

    "dns": ["", ""]

In this example, Google’s and Cloudflare’s DNS servers will be used in place of the host’s DNS servers for all containers.

Save the file and restart the Docker daemon with:

sudo service docker restart

Fixing DNS Or Internet Issues Locally For An Affected Container #

If you’d only want to change the DNS server for a single container, you can directly add the new addresses to the container as shown below:

    image: you/yourimage
		# regular container config...
      - ""
      - ""

Conclusion #

This was a really straightforward fix and I hope this helps. If you’d love to learn more, check out this article by Robin

Till we meet again, bye!