Docker-spy provides a DNS service based on Docker container events. It keeps an in-memory database of records that map container hostnames to ip addresses. When containers are start/stopped/destroyed it keeps track of their location.
It is specifically targeted at small local development environments where you want an easy way to connect with your containers. Originally developed as part of my blog series on running a local Puppet dev stack with Docker.
The easiest way to run docker-spy is through Docker. The image is based on the scratch image (basically a zero sized image) and contains only the compiled Go executable.
Docker-spy can be configured through a number of environment variables:
Docker-spy will consider all DNS requests that end with the above configured DNS_DOMAIN to be internal requests that should be mapped to a container. All other DNS requests are forwarded to the recursor, so the DNS server should be relatively transparent.
Before starting docker-spy you should know the following things about your system:
ifconfig
and look for the Docker0 bridge entry. OSX users should first ssh into the boot2docker virtual machine with boot2docker ssh
boot2docker ip
to find out what it is.To run docker-spy you can issue the following command:
docker run --name docker_spy -p 53:53/udp -p 53:53 -v /var/run/docker.sock:/var/run/docker.sock iverberk/docker-spy
This maps the Docker socket as a volume in the container so that events may be tracked and it publishes port 53 on udp/tcp to the host. Add a -d
parameter to run the container in the background. You may then inspect the logs with docker logs docker_spy
To have seamless DNS resolution and access to your containers you should perform the following steps:
nameserver x.x.x.x
(x.x.x.x should be replaced with the Docker bridge IP address that you looked up earlier)sudo route -n add -net 172.17.0.0 192.168.59.104
To have automatic DNS resolution of your containers you should update your /etc/resolv.conf and add the Docker bridge IP address as a resolver (usually 172.17.42.1 but check it with ifconfig to be certain).
Docker-spy is really young and has a lot of rough edges. I wanted to have a basic, working solution before adding nice-to-haves. It is also my first Go program so there will probably be less then idiomatic constructs in the program. Fixes and enhancements are gladly accepted. Issues may be filed against the github repository.
To build docker-spy just install the go build environment and run go build -o docker-spy *.go
in the directory.