Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker network show DNS entries

Tags:

docker

dns

I'm trying to debug a container dns resolving issue on ubuntu linux docker. As described here https://docs.docker.com/config/containers/container-networking/#dns-services docker usage a embedded DNS server inside container. Are there any commands that list Docker’s embedded DNS server entries ? ( like entries in /etc/resolv.conf) I have tried docker inspect and docker network inspect. Also tried starting dockerd is debug mode but have not found anything useful.

It does show some config file read like below.

INFO[2020-07-13T14:39:58.517777580+05:45] detected 127.0.0.53 nameserver, assuming systemd-resolved, so using resolv.conf: /run/systemd/resolve/resolv.conf  

But I wanted to list the runtime dns entries of dockerd network with dns addresss 127.0.0.11. Is it possible ?

like image 845
tinker Avatar asked Jul 13 '20 09:07

tinker


People also ask

Does Docker have DNS?

Problem solved. Docker containers take DNS IPs from the host machine, which is managed by systemd-resolve . Those IPs themselves are the cloud provider's DNS.

How does Docker do DNS?

Docker uses embedded DNS to provide service discovery for containers running on a single Docker Engine and tasks running in a Docker Swarm. Docker Engine has an internal DNS server that provides name resolution to all of the containers on the host in user-defined bridge, overlay, and MACVLAN networks.


1 Answers

It is possible, but you have to parse the JSON printed by docker network inspect.

Run docker network ls to get the running networks names, and then docker network inspect NETWORK_NAME to see the containers in it.

Look for the "Containers" keyword in the JSON, it is a list of connected devices. Look for the instance with the "IPv4Address": "127.0.0.11/24" entry, the "Name" key is the DNS name.

I.E. countly_countly-endpoint is the DNS name that resolves to ip 10.0.8.4/24:

           "lb-countly_countly": {
                "Name": "countly_countly-endpoint",
                "EndpointID": "9f7abf354b5fbeed0be6483b53516641f6c6bbd37ab991544423f5aeb8bdb771",
                "MacAddress": "02:42:0a:00:08:04",
                "IPv4Address": "10.0.8.4/24",
                "IPv6Address": ""
            }

Note that countly_ is the network namespace that matches the network name in docker network ls, that way you can be sure that they are unique and configure your services to talk to each other using the DNS name according to the rule of NETWORK-NAME_SERVICE-NAME.

like image 105
JeanPaulDepraz Avatar answered Oct 16 '22 16:10

JeanPaulDepraz