Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
faa0db7
adding version to docker client creation
Jul 30, 2014
abfe416
adding version= to client
Jul 30, 2014
bed9d61
oops
Jul 31, 2014
2a4eb87
heavy modification for troubleshooting
Aug 5, 2014
5f46b4c
.
Aug 5, 2014
051da46
fixed name lookup, string comp
Aug 5, 2014
b1aed7c
change descript
Aug 5, 2014
29a7ba3
update requirements to newer dockerpy
Aug 5, 2014
0bf4031
.
Aug 5, 2014
b4c691d
change apierror location
Aug 6, 2014
ee39e41
Merge branch 'master' of https://github.com/bcicen/docker_dns
Aug 6, 2014
bde11f4
changing default bind port to 53000
Aug 12, 2014
a63de16
adding default timeout of 30 to client obj
Aug 12, 2014
05fe5eb
Revert "changing default bind port to 53000"
Aug 13, 2014
6f77542
support for nat discovery via SRV
ioggstreamhat Oct 31, 2014
e67cb57
little tweaks
ioggstream Oct 31, 2014
4d2e693
merge error logging from miracle2k
ioggstream Oct 31, 2014
77c1d87
moved helpers functions in utils.py
ioggstream Oct 31, 2014
e673c9e
use in-addr arpa name to return the associated ip.
ioggstream Nov 2, 2014
3a413df
fix twisted version to 14.
ioggstream Nov 2, 2014
8e858fd
use docker events interface to get infos
ioggstream Jan 19, 2015
b8562db
fix: instantiate event manager in .tac file
ioggstream Jan 19, 2015
5c481aa
add existing containers
ioggstream Jan 22, 2015
866f377
initialize db
ioggstream Jan 22, 2015
78dd9b5
refactoring: starts working
ioggstream Jan 29, 2015
ff480e6
refactor: tests
ioggstream Jan 29, 2015
f4f4e17
merge: with github
ioggstream Feb 6, 2015
7852602
fix: set docker api version
ioggstream Feb 6, 2015
61f5bc4
Merge branch 'refactoring_1' of https://github.com/ioggstream/docker_…
ioggstream Feb 6, 2015
f1ba816
fix: import in test_srv
ioggstream Feb 6, 2015
16ba276
Merge branch 'refactoring_1' of https://github.com/ioggstream/docker_…
ioggstream Feb 6, 2015
10cf6e6
enh: using twistd plugin for passing arguments
ioggstream Feb 8, 2015
165955e
fix: nose moved to test_requirements.txt
ioggstream Feb 9, 2015
cc52cef
feat: json config file
ioggstream Feb 9, 2015
0fa303b
enh: refactoring tests
ioggstream Feb 9, 2015
487f2ee
merge: from master
ioggstream Feb 11, 2015
032034d
added a small REST console to check database
ioggstream Feb 13, 2015
13f21bc
enh: more logs
ioggstream Feb 13, 2015
58f851b
Merge branch 'refactoring_1' of https://github.com/ioggstream/docker_…
ioggstream Feb 13, 2015
8fecd57
add: console on port 8080
Feb 13, 2015
6212723
fix: big limiting received events
Feb 13, 2015
8cab1c5
refresh hosts via console
ioggstream Feb 20, 2015
00884d0
autopep8
ioggstream Feb 21, 2015
9e9be7a
cleanup code
ioggstream Feb 22, 2015
8da174b
added pypy
ioggstream Feb 22, 2015
76c5129
fix: pep8
ioggstream Feb 23, 2015
60c591f
fix: pep8
ioggstream Feb 23, 2015
3ba6a8d
ci: removed pylint
ioggstream Feb 23, 2015
3cb5054
moved test requirements outside module
ioggstream Feb 23, 2015
e47b6df
removed pypy
ioggstream Feb 23, 2015
a4d6d17
fix: test_requirements
ioggstream Feb 24, 2015
69d24a9
feat: PTR record support
ioggstream Feb 24, 2015
d7c9bfa
first sftp access to volumes
ioggstream Mar 1, 2015
760d90d
feat: working sftp access to volumes
ioggstream Mar 2, 2015
8f13cb0
fix: test sftp volumes
ioggstream Mar 2, 2015
24dae04
added sftp doc
ioggstream Mar 2, 2015
dd1bcb6
fix: config file now overrides command lines, return empty records on…
ioggstream Apr 8, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ language: python
python:
- "2.7"
install:
- sudo pip install -r test_requirements.txt --use-mirrors
- pip install -r test_requirements.txt
before_script:
- pep8 *.py
- pylint --rcfile=pylint.conf *.py
- pep8 dockerdns/*.py twisted/plugins/*py dockerdns/sftp/*py
# - pylint --rcfile=pylint.conf dockerdns/*.py twisted/plugins/*py
script:
- ./docker_dns_test.py
- nosetests -v -w test
29 changes: 29 additions & 0 deletions README.bind
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Configure with bind
===================


If you use a local bind instance you can configure twistd dns with bind adding this stanza to named.conf. For now this requires to disable EDNS, which is not actuallyimplemented in docker_dns.


zone "docker" {
type forward;
forwarders {
127.0.0.64;
};
};


And binding your local docker_dns server on the following
loopback ip: 127.0.0.64


Configure with dnsmasq
======================

You can use twistd dns with dnsmasq using the following file:

# Config file for /etc/dnsmasq.d/dockerdns.conf
port=53

# Forward only .docker requests...
server=/docker/127.0.0.64#10053
145 changes: 73 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,61 @@
Docker DNS
==========
[![Build Status](https://travis-ci.org/infoxchange/docker_dns.png?branch=master)](https://travis-ci.org/infoxchange/docker_dns)

A simple Twisted DNS server using custom TLD and Docker as the back end for IP
resolution.
A simple Twisted DNS server using custom TLD and Docker Event interface as the back end for IP
resolution. As a plus you get a sperimental SFTP server to access Docker Volumes.

To look up a container:
- 'A' record query container's hostname with no TLD. Must be an exact match
- 'A' record query an ID that will match a container with a docker inspect
command with '.docker' as the TLD. eg: 0949efde23b.docker
Containers can be found by:
- image name
- container name
- hostname
- ip

eg: here are some examples

#host busybox.*.docker # search all busybox containers
#host 26ed50b1bf59.docker # search a container by hostname (not by ID!)
#host nice_bohr.docker # search a container by name

You can lookup different records:
- 'A' record: query a container NAME or HOSTNAME that will match a container with a docker inspect
command with '.docker' as the TLD. eg: mysql_server1.docker
- 'SRV' record query exposing the NAT informations (more to come!)
- 'PTR' record, with reverse pointer

Note: This fork of docker_dns *always* requires to query using a TLD (by default .docker)

Install/Run
-----------

Just install from requirements (in a virtualenv if you'd like)

pip install -r requirements.txt --use-mirrors
#pip install -r requirements.txt

That's it! To run, just
That's it! To run, remember that you may need to set user/group ids on
the process

twistd -y docker_dns.py

#sudo twistd -gdocker -y dockerdns -p 53

This will start a DNS server on port 53 (default DNS port). To make this
useful, you probably want to combine it with your regular DNS in something like
Dnsmasq.
useful, you probably want to combine it with your regular DNS in something like Dnsmasq.

You can get configuration parameters with

#sudo twistd dockerdns --help


Examples
There's a simple HTTP console to check the internal mappings. You can curl it with

#curl -v http://localhost:8080/{hostname,image,name,id,ping,help,ip}/{optional_key}

DNS Examples
--------
Dig output is shortened for brevity. We have Docker containers like this:

ID IMAGE COMMAND CREATED STATUS PORTS
26ed50b1bf59 ubuntu:12.04 /bin/bash 4 seconds ago Up 4 seconds
0949efde23bf ubuntu:12.04 /bin/bash 18 hours ago Up 18 hours
ID IMAGE STATUS Names
26ed50b1bf59 ubuntu:12.04 Up 1 hour sad_turing
0949efde23bf ubuntu:12.04 Up 18 hours happy_bohr

0949efde23bf has:

Expand All @@ -45,36 +69,22 @@ Dig output is shortened for brevity. We have Docker containers like this:
- IP: 172.17.0.3
- Hostname: my-thing

Container IDs are variable length. You use the same input as the Docker `inspect` command, so they can be long:

dig 0949efde23bf017.docker
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51840
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; ANSWER SECTION:
0949efde23bf017.docker. 10 IN A 172.17.0.2

Search by Hostname (uses default or explicit hostname)

Or they can be short:
#dig +short 26ed50b1bf59.docker
172.17.0.2

dig 0949.docker
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42797
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
#dig +short my-thing.docker
172.17.0.3

;; ANSWER SECTION:
0949.docker. 10 IN A 172.17.0.2
Search by Names (works only the first Name)

And the other container:
#dig +short sad_turing.docker
172.17.0.2

dig 26ed50b1bf59.docker
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25901
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
#dig +short happy_bohr.docker
172.17.0.3

;; ANSWER SECTION:
26ed50b1bf59.docker. 10 IN A 172.17.0.3

When a container doesn't exist, no answer is given:

Expand All @@ -83,58 +93,49 @@ When a container doesn't exist, no answer is given:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 24269
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0

You can look up by hostname by removing the .docker TLD:
You can search by image, like skydock:

dig 0949efde23bf
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 61822
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
dig +short ubuntu.*.docker
172.17.0.2
172.17.0.3

;; ANSWER SECTION:
0949efde23bf. 10 IN A 172.17.0.2
Nat discovery: you can discover natted ports with queries like this one

Here's a manually defined hostname:
dig _8080._tcp.my-thing.docker srv
;; ANSWER SECTION:
_8080._tcp.jboss631.docker. 10 IN SRV 100 100 18080 192.168.204.17.

dig my-thing
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3355
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; ANSWER SECTION:
my-thing. 10 IN A 172.17.0.3
SFTP Examples
-------------
To access the /myshare volume on the container jboss631, just:

And the host name that would have been automatically assigned for the above
container:
#sftp -P10022 jboss631@localhost # empty password
#ls /
/myshare


dig 26ed50b1bf59
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 12687
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0

Configuration
-------------
Config is done in the `config.py` file. There's a skeleton in
`config.py.sample`. Below are the default config values. Currently,
Config is done in the `dockerdns.json` file. There's a skeleton in
`dockerdns.json.sample`. Below are the default config values. Currently,
configuration is rather limited.

CONFIG = {
# URL to connect to the Docker API. docker-py defaults to
# unix://var/run/docker.sock
{
"#": "# URL to connect to the Docker API. docker-py defaults to unix://var/run/docker.sock",
'docker_url': None

# socket.bind defaults to 0.0.0.0
"#": "# socket.bind defaults to 0.0.0.0",
'bind_interface': '',
'bind_port': 53,
'bind_protocols': ['tcp', 'udp'],

# When the request matches no docker container, we should return
# NXDOMAIN, however the OS interprets this as "doesn't exist anywhere"
# so things like google.com fail. This will return SERVFAIL rather than
# NXDOMAIN so secondary DNS is used
"#": "Return SERVFAIL instead of NXDOMAIN if no matching container found"
'no_nxdomain': True,

# Makes successful requests authoritive
'authoritive': True,
"#": "Makes successful requests authoritative",
'authoritative': True,
}

Contributing
Expand Down
8 changes: 0 additions & 8 deletions config.py.sample

This file was deleted.

Loading