Public | Automated Build

Last pushed: 9 months ago
Short Description
Self-contained automatic DNS
Full Description

docker-dns

Automatic container DNS for Docker in a single Python file.

Note that docker-dns-rest expands on this, adding a REST API to add and remove domain names dynamically, allowing multiple domain names to be associated with containers, either by name or container ID. It also includes support for wildcards.

Usage

Run some containers:

% docker run -d --name foo ubuntu bash -c "sleep 600"

Start up dockerdns:

% docker run --name dns -v /var/run/docker.sock:/docker.sock phensley/docker-dns \
    --domain example.com

Start more containers:

% docker run -d --name bar ubuntu bash -c "sleep 600"

Check dockerdns logs:

% docker logs dns
2014-10-08T20:45:37.349161 [dockerdns] table.add dns.example.com -> 172.17.0.3
2014-10-08T20:45:37.351574 [dockerdns] table.add foo.example.com -> 172.17.0.2
2014-10-08T20:45:37.351574 [dockerdns] table.add bar.example.com -> 172.17.0.4

Query for the containers by hostname:

% host foo.example.com 172.17.0.3
Using domain server:
Name: 172.17.0.3
Address: 172.17.0.3#53
Aliases:

foo.example.com has address 172.17.0.2
foo.example.com has address 172.17.0.2

Use dns container as a resolver inside a container:

% docker run -it --dns $(docker inspect -f '{{.NetworkSettings.IPAddress}}' dns) \
    --dns-search example.com ubuntu bash

root@95840788bf08:/# cat /etc/resolv.conf
nameserver 172.17.0.3
search example.com

root@95840788bf08:/# ping foo
PING foo.example.com (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.112 ms
64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.112 ms

Names not rooted in example.com will be resolved recursively using Google's resolver 8.8.8.8 by default:

root@95840788bf08:/# ping github.com
PING github.com (192.30.252.128) 56(84) bytes of data.
64 bytes from 192.30.252.128: icmp_seq=1 ttl=61 time=21.3 ms

To disable recursive resolution, use the --no-recursion flag:

% docker run --name dns -v /var/run/docker.sock:/docker.sock phensley/docker-dns \
    --domain example.com --no-recursion

Now names not rooted in example.com will fail to resolve:

% docker run -it --dns $(docker inspect -f '{{.NetworkSettings.IPAddress}}' dns) \
    --dns-search example.com ubuntu bash
root@4d15342387b0:/# ping github.com
ping: unknown host github.com

License

Copyright (c) 2014 Patrick Hensley

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Docker Pull Command
Owner
phensley
Source Repository

Comments (5)
unnull
10 months ago

Thank your the contribution.
But I get an Exception KeyError "KeyError(139651258305584,) in <module 'threading' from '/usr/lib/python2.7/threading.pyc'> ignored " and no any log output when running the docker image. The host system is centos 6.5, kernel update to 3.10.104. and docker version is 1.7.1. Would you please offer me some suggestion?

eorlovsky
a year ago

Does it work with mac os under docker-machine ?

marakaidocker
a year ago

Extremely useful.

But I noticed that renaming a container doesn't seem to get picked up. It's possible to restart the dns container, but that leads to both old and new name now appearing (which may be a good thing, but should maybe be an option).

salvozappa
2 years ago

This is very handy and easy to use. Thank you!

plaurin
3 years ago

This is really useful for me, keep up the good work!