Public Repository

Last pushed: a year ago
Short Description
DNS + Docker + Docker Compose [+ osx] suddenly is way more awesome
Full Description

Damn Simple DNS Proxy (DSDP)

Created to solve a single problem well. Run this container in a docker-compose
v2 file and it will proxy dns requests to the docker daemon's embedded dns
server. Technically this will work for any docker user network, but its
designed to be used with docker-compose.

In the following example, docker-compose spins up redis and DSDP, then connects
to redis from a container using docker's embedded dns server. Then we query DSDP
from the host machine which returns the ip of the redis server as expected.

.../damn-simple-dns-proxy $ cd example
.../example $ docker-compose run redis-cli
Creating network "example_default" with the default driver
Creating example_redis_1
Creating example_dns-proxy_1
redis:6379> set foo bar
redis:6379> get foo

.../example $ docker ps
CONTAINER ID        IMAGE                              COMMAND                  CREATED             STATUS              PORTS                   NAMES
6877be6c36a0        carlsverre/damn-simple-dns-proxy   "/dsdp"                  22 seconds ago      Up 7 seconds>53/udp   example_dns-proxy_1
e18411bfec56        redis                              ""   22 seconds ago      Up 7 seconds        6379/tcp                example_redis_1

.../example $ dig +short @ redis.docker

If you are on a mac you can forward packets to the new network, and setup your
dns resolver like so:

.../example $ cat /etc/resolver/docker
domain docker.
.../example $ sudo route -n add $(docker-machine ip)
add net gateway
.../example $ python -c "import socket; print(socket.gethostbyname('redis.docker'))"
.../example $ python -c "import redis; print(redis.Redis('redis.docker').get('foo'))"

Remember to cleanup after playing with the example. :)

.../example $ docker-compose down
Stopping example_dns-proxy_1 ... done
Stopping example_redis_1 ... done
Removing example_redis-cli_run_1 ... done
Removing example_dns-proxy_1 ... done
Removing example_redis_1 ... done
Removing network example_default
Docker Pull Command