Unable to resolve a container hostname with correct IP from DNS


I wonder what I do wrong since I’m not able to resolve my hostname thru my DNS? Please see my steps below.

From HOST the IP is correctly resolved ‘mysql.example.com’ with the correct address

ubuntu@docker:~$ host mysql.example.com
Using domain server:

mysql.example.com has address

My /etc/default/docker configuration (and yes: I did a service docker restart)

DOCKER_OPTS="–dns --dns"

Now try to fire up a container pointing at the correct DNS with search domain set up to ‘example.com

$ ubuntu@docker:~$ docker run --dns= --dns-search=example.com -h mysql.example.com -it ubuntu:trusty

Inside the newly started container the hostname is correctly set up

root@mysql:/# hostname

Inside my container the ‘resolv.conf’ is correctly set up

root@mysql:/# cat /etc/resolv.conf
search example.com

Still, the container has not been able to be assigned with the IP from configured DNS !?!?!

root@mysql:/# ip a
92: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
inet scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:2/64 scope link
valid_lft forever preferred_lft forever

Now, I installed DnsUtils inside the container

root@mysql:/# apt-get install dnsutils
Reading package lists… Done
The following NEW packages will be installed:
bind9-host dnsutils geoip-database krb5-locales libbind9-90 libdns100
libgeoip1 libgssapi-krb5-2 libisc95 libisccc90 libisccfg90 libk5crypto3
libkeyutils1 libkrb5-3 libkrb5support0 liblwres90 libxml2 sgml-base xml-core
0 upgraded, 19 newly installed, 0 to remove and 0 not upgraded.

And finally, made a simple host lookup; which resolves the correct address

root@mysql:/# host mysql.example.com
mysql.example.com has address

The question remains: how come the container is designated with a wrong host ip? It should be ‘’, but the address resolved from my DNS ‘’.

What is the correct way to manage DNS configuration with Docker?

Thanks to BlackthornYugen on docker@irc.freenode.net I figured out a solution on this. My problem wasn’t the dns; it was related to static IP or DHCP assignment. As of Docker Engine v1.10.1+ there is an option for assigning a static ip on a user defined network.

$ docker network create --subnet= mynet123 $ docker run --net=mynet123 --dns= --dns-search=example.com -h mysql.example.com --ip $(host -i mysql.example.com | sed -e "s/.*\ //" ) -it ubuntu:trusty
By doing a reverse NS lookup for --ip option using a bash eval; it seems to be sorted after all :slightly_smiling:

The container’s /etc/hosts now reads: mysql.example.com mysql