rawdns is a DNS forwarder that allows for DNS requests to return the IP addresses of Docker containers directly.

One way to think of this is that it’s essentially the most basic form of service discovery. Unlike other similar solutions, no caching or intermediary data store is ever used, so there’s no chance of stale data unless it comes from Docker itself. The downside to this method is that the Docker API response speed becomes the bottleneck, but for many common uses that’s a perfectly acceptable tradeoff.

For example, if a local container named “app” exists, then a DNS request for “app.docker” would return the IP address of that container. Likewise, if the “app” container has a linked database container whose alias name is “db” (--link some-other-container:db), then a request for “db.app.docker” would return the IP address of the linked database container.

The primary use-case for such a thing is the ability to spin up containers on a development machine and reference them right away via DNS (http://container-name.docker in a browser, for example) without resorting to invoking docker inspect by hand (to look up the container’s IP address). To illustrate, after invoking docker run -d --name owncloud owncloud, immediately opening a browser window to http://owncloud.docker will connect to that container’s port 80, ready to configure and use ownCloud.

See the repository on GitHub for more configuration examples, especially setting up a local transparent APT packages cache via apt-cacher-ng.

If you’re interested in setting up NGINX to utilize rawdns for routing web traffic to containers (without using --link or explicit port mappings on your individual containers), see github.com/infosiftr/nginx-conf.d (especially example/default.conf).

GitHub: github.com/tianon/rawdns

git clone https://github.com/tianon/rawdns.git

Docker: tianon/rawdns

docker run \
	--detach \
	--name rawdns \
	--publish 53:53/udp \
	--restart always \
	--volume /var/run/docker.sock:/var/run/docker.sock \

Debian: rawdns

apt-get install rawdns

TL;DR: DNS A request → Docker API inspect request/response → container IP extraction → DNS A response

Home | About Us

© InfoSiftr 2017.   All Rights Reserved.