Docker does not resolve hostname

I need to know the hostnames (or IP addresses) of some container running on the same machine. Since I've already commented here (but haven't answered yet), I'm using docker-compose

. The documentation says that it will automatically create a hostname entry for the entire container defined in the same file docker-compose.yml


Each container for a service joins the network by default and is accessible to and discoverable by other containers on that network by a hostname that is identical to the container name.

But I don't see any host entry through docker exec -it my_container tail -20 /etc/hosts

. I also tried adding links

to my container but nothing changed.


source to share

1 answer

Docker 1.10 introduced some new networking features that include an internal DNS server that looks up the host.

On the default bridged network (docker0), lookups continue to function across /etc/hosts

as they use. /etc/resolv.conf

will point to your host converters.

On a user-defined network, Docker will use an internal DNS server. /etc/resolv.conf

will have an internal IP for the Docker DNS server. This setting allows bridged, custom, and overlay networks to work in a similar manner. Thus, the overlay network on the swarm will populate the host data from the entire swarm, just like a local bridged network does.

The "obsolete" setting has been retained so that new network functions can be introduced without affecting existing settings.


The DNS resolver can provide an IP address for the docker compose service through the name of that service.

For example, if the service web

and are defined db

, and the service is db

scaled to 3

, all instances db

will be resolved:

$ docker-compose run --rm web nslookup db

Name:      db
Address 1: composenetworks_db_2.composenetworks_mynet
Address 2: composenetworks_db_3.composenetworks_mynet
Address 3: composenetworks_db_1.composenetworks_mynet




All Articles