Docker Community Forums

Share and learn in the Docker community.

How reaching the other containers by name works

I am setting up a set of containers on a webserver. There’s an Apache http server, nginx http server, MySQL server and Redis server. Plus a container I use to test connectivity from.

I have created a network with docker network create www --subnet=172.18.0.0/16, and when I run those containers, I do it with the --name="etc", --network www, and --ip 172.18.0.n parameters. I have verified that thus the MySQL server is reachable from the Apache server by simply using the MySQL container name instead of IP address.

But when I test this inter-container connectivity from the testing container, using ping, I get strange behavior: the name is appended with “.www”

/# ping mysql
PING mysql0 (172.18.0.3) 56(84) bytes of data.
64 bytes from mysql0.www (172.18.0.3): icmp_seq=1 ttl=64 time=0.093 ms
64 bytes from mysql0.www (172.18.0.3): icmp_seq=2 ttl=64 time=0.062 ms

# ping Apache2-PHP5.6
PING Apache2-PHP5.6 (172.18.0.2) 56(84) bytes of data.
64 bytes from Apache2-PHP5.6.www (172.18.0.2): icmp_seq=1 ttl=64 time=0.086 ms
64 bytes from Apache2-PHP5.6.www (172.18.0.2): icmp_seq=2 ttl=64 time=0.060 ms

This leads to my questions:

  • From where that .www appeared? How exactly this reaching other containers by name work? Is there a DNS hidden in the Docker network?
  • Does that put some restrictions on the characters used in the names?
  • Is there any relation to the --hostname parameter?
  • If the containers can be reached reliably via their name, is it ok not to explicitly set containers’ IP addresses?