Skip to content

Instantly share code, notes, and snippets.

@oranheim
Last active March 7, 2016 20:01
Show Gist options
  • Save oranheim/a416d30e5da82f7b8ab2 to your computer and use it in GitHub Desktop.
Save oranheim/a416d30e5da82f7b8ab2 to your computer and use it in GitHub Desktop.
Docker DNS with BIND
# From HOST the IP is correctly resolved 'mysql.example.com' with the correct address <===
ubuntu@docker:~$ host mysql.example.com 172.17.0.1
Using domain server:
Name: 172.17.0.1
Address: 172.17.0.1#53
Aliases:
mysql.example.com has address 172.17.0.10
# My /etc/default/docker configuration (and yes: I did a service docker restart)
DOCKER_OPTS="--dns 172.17.0.1 --dns 8.8.8.8"
# 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=172.17.0.1 --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
mysql.example.com
# Inside my container the 'resolv.conf' is correctly set up
root@mysql:/# cat /etc/resolv.conf
search example.com
nameserver 172.17.0.1
# 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 172.17.0.2/16 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
[..cut..]
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.
[..cut..]
# And finally, made a simple host lookup; which resolves the correct address
root@mysql:/# host mysql.example.com
mysql.example.com has address 172.17.0.10
# ==> The question remains: how come the container is designated with a wrong host ip !?!? <==
# Resolution figured out. Please check out the Docker Forums post: https://forums.docker.com/t/unable-to-resolve-a-container-hostname-with-correct-ip-from-dns/7188
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment