Giter VIP home page Giter VIP logo

docker-dns-proxy's Introduction

docker-dns-proxy

app1.example.00:80 -> (dnsmasq, nginx) -> app1.example container in "00" custom docker 1.9 network

--- docker machine --------------------------
------ net: 00 ------------------------------
 [app1.example], [app2.example] ...
   ^
   | http://app1.example.00/ (e.g. 172.19.0.2)
   |
   |              /etc/hosts    --address=/.00/192.168.99.100
 [nginx] ------> [dnsmasq_in]  [dnsmaq_out]
- :80 ----------- :5353 ---------- :53 ------ expose port
   ^                                ^
   | http://app1.example.00/ (192.168.99.100)
   |                                |
---- localhost ------------------------------
 [browser] <---------> [/etc/resolver/docker]

Prerequisites

  • docker 1.9

(I tested on OS X 10.10.5 with docker 1.9 installed by Kitematic.)

Assumptions

  • A docker-machine running on 192.168.99.100
  • You use docker custom network named 00
  • Use .00 as the TLD

Of course, you can alter those default if you wish.

Usage by example

Let localhost resolve .00 TLD for the docker machine

sudo bash -c 'echo "nameserver 192.168.99.100" > /etc/resolver/00'

Create a custom docker network, 00

$ docker network create 00

Run an app container for test

Run python SimpleHTTPServer for example as app1.example.

$ docker run -it --rm --net 00 --name app1.example python:2 python -m SimpleHTTPServer 80
Serving HTTP on 0.0.0.0 port 80 ...

Build and run docker-dns-proxy

$ docker-compose build
$ docker-compose --x-networking up
Starting dockerdnsproxy_dnsmasq_out_1
Starting dockerdnsproxy_dnsmasq_in_1
Recreating dockerdnsproxy_nginx_1
Attaching to dockerdnsproxy_dnsmasq_out_1, dockerdnsproxy_dnsmasq_in_1, dockerdnsproxy_nginx_1
...

Test!!

Enter http://app1.example.00 in your browser or curl http://app1.example.00.

https://gyazo.com/75100cc61960cf330f50748ad47cf5a2

Reload dnsmasq

If you restart the app container or run another app container, you may get 502 Bad Gateway. dnsmasq won't reload /etc/hosts automatically. You need let the dnsmasq process to reload /etc/hosts.

docker kill -s HUP dockerdnsproxy_dnsmasq_in_1

or

docker-compose restart dnsmasq

or simply shutdown and up docker-compose.

(I want a simple "watch /etc/hosts and HUP dnsmasq container if I can...)

docker-dns-proxy's People

Contributors

hiroshi avatar

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.