Git Product home page Git Product logo

docker-dns's Introduction

docker-dns

Automatic container DNS for Docker in a single Python file.

Note that docker-dns-rest expands on this, adding a REST API to add and remove domain names dynamically, allowing multiple domain names to be associated with containers, either by name or container ID. It also includes support for wildcards.

Usage

Run some containers:

% docker run -d --name foo ubuntu bash -c "sleep 600"

Start up dockerdns:

% docker run --name dns -v /var/run/docker.sock:/docker.sock phensley/docker-dns \
    --domain example.com

Start more containers:

% docker run -d --name bar ubuntu bash -c "sleep 600"

Check dockerdns logs:

% docker logs dns
2014-10-08T20:45:37.349161 [dockerdns] table.add dns.example.com -> 172.17.0.3
2014-10-08T20:45:37.351574 [dockerdns] table.add foo.example.com -> 172.17.0.2
2014-10-08T20:45:37.351574 [dockerdns] table.add bar.example.com -> 172.17.0.4

Query for the containers by hostname:

% host foo.example.com 172.17.0.3
Using domain server:
Name: 172.17.0.3
Address: 172.17.0.3#53
Aliases:

foo.example.com has address 172.17.0.2
foo.example.com has address 172.17.0.2

Use dns container as a resolver inside a container:

% docker run -it --dns $(docker inspect -f '{{.NetworkSettings.IPAddress}}' dns) \
    --dns-search example.com ubuntu bash

root@95840788bf08:/# cat /etc/resolv.conf
nameserver 172.17.0.3
search example.com

root@95840788bf08:/# ping foo
PING foo.example.com (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.112 ms
64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.112 ms

Names not rooted in example.com will be resolved recursively using Google's resolver 8.8.8.8 by default:

root@95840788bf08:/# ping github.com
PING github.com (192.30.252.128) 56(84) bytes of data.
64 bytes from 192.30.252.128: icmp_seq=1 ttl=61 time=21.3 ms

To disable recursive resolution, use the --no-recursion flag:

% docker run --name dns -v /var/run/docker.sock:/docker.sock phensley/docker-dns \
    --domain example.com --no-recursion

Now names not rooted in example.com will fail to resolve:

% docker run -it --dns $(docker inspect -f '{{.NetworkSettings.IPAddress}}' dns) \
    --dns-search example.com ubuntu bash
root@4d15342387b0:/# ping github.com
ping: unknown host github.com

License

Copyright (c) 2014 Patrick Hensley

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

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.