Giter Club home page Giter Club logo

damn-simple-dns-proxy's Introduction

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
OK
redis:6379> get foo
"bar"
redis:6379>

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

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

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
nameserver 172.18.0.1
domain docker.
.../example $ sudo route -n add 172.18.0.0/16 $(docker-machine ip)
add net 172.18.0.0: gateway 192.168.99.100
.../example $ python -c "import socket; print(socket.gethostbyname('redis.docker'))"
172.18.0.2
.../example $ python -c "import redis; print(redis.Redis('redis.docker').get('foo'))"
bar

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.