Giter VIP home page Giter VIP logo

rawdns's Introduction

rawdns

Save as /etc/rawdns/config.json:

{
	"docker.": {
		"type": "containers",
		"socket": "unix:///var/run/docker.sock"
	},
	"local.": {
		"type": "forwarding",
		"nameservers": [ "192.168.1.1" ]
	},
	".": {
		"type": "forwarding",
		"nameservers": [ "8.8.8.8", "8.8.4.4" ]
	}
}

Then:

$ docker run --rm -p 53:53/udp -v /var/run/docker.sock:/var/run/docker.sock -v /etc/rawdns/config.json:/etc/rawdns/config.json:ro tianon/rawdns rawdns /etc/rawdns/config.json
2014/09/23 14:46:10 listening on domain: docker.
2014/09/23 14:46:10 listening on domain: local.
2014/09/23 14:46:10 listening on domain: .

The most-specific domain gets the request (ie, if you have both docker. and containers.docker. and you do a lookup for something.containers.docker, you'll get back the IP of the container named something).

The default configuration only includes docker. going to /var/run/docker.sock and . going to 8.8.8.8+8.8.4.4.

wat

Since DNS is a protocol (which is a type of API), and Docker has an API, it makes a lot more sense to have DNS be a raw interface to Docker than it does to treat DNS like a database and try to synchronize the two data sources.

why

I've eventually grown to dislike every "Docker DNS" project for one reason or another, and usually the misgivings boil down to treating DNS like a database, which reminds me of my favorite thing to say about databases: if you have the same data in two places, they are guaranteed to eventually get out of sync in some way (no matter how clever you or your code are).

how

This is implemented by borrowing the core of SkyDNS, github.com/miekg/dns. It's a really great, but very raw, DNS library for Go that makes it really easy to write a DNS server or client. One of the explicit design goals of the project is "If there is stuff you should know as a DNS programmer there isn't a convenience function for it."

SHOW ME

$ dig @localhost dns.docker

; <<>> DiG 9.9.5 <<>> @localhost dns.docker
; (2 servers found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18138
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;dns.docker.			IN	A

;; ANSWER SECTION:
dns.docker.		0	IN	A	172.18.0.30

;; Query time: 1 msec
;; SERVER: ::1#53(::1)
;; WHEN: Wed Sep 24 23:06:33 MDT 2014
;; MSG SIZE  rcvd: 54

$ ping dns.docker
PING dns.docker (172.18.0.30) 56(84) bytes of data.
64 bytes from 172.18.0.30: icmp_seq=1 ttl=64 time=0.025 ms
64 bytes from 172.18.0.30: icmp_seq=2 ttl=64 time=0.049 ms
64 bytes from 172.18.0.30: icmp_seq=3 ttl=64 time=0.041 ms
^C
--- dns.docker ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.025/0.038/0.049/0.011 ms

swarm support

rawdns can be used with swarm by creating a configuration that provides the socket details using the tcp:// scheme. You will also need to enable swarmnode by setting it to true. The swarmnode option enables rawdns to look at the Node section of the inspect API response for the external/host IP address.

Example swarm configuration:

{
    "swarm.": {
        "type": "containers",
        "socket": "tcp://192.168.99.100:3376",
        "swarmnode": true,
        "tlsverify": true,
        "tlscacert": "/var/lib/boot2docker/ca.pem",
        "tlscert": "/var/lib/boot2docker/server.pem",
        "tlskey": "/var/lib/boot2docker/server-key.pem"
    },
    "docker.": {
        "type": "containers",
        "socket": "unix:///var/run/docker.sock"
    },
    "local.": {
        "type": "forwarding",
        "nameservers": [ "172.17.42.1" ]
    },
    ".": {
        "type": "forwarding",
        "nameservers": [ "8.8.8.8", "8.8.4.4" ]
    }
}

Example usage:

$ docker run --name dns --rm -it \
    -p 53:53/udp \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /var/lib/boot2docker:/var/lib/boot2docker \
    -v /etc/rawdns/config.json:/etc/rawdns/config.json:ro \
    tianon/rawdns rawdns /etc/rawdns/config.json

2015/09/14 21:50:49 rawdns v1.2 (go1.4.2 on linux/amd64; gc)
2015/09/14 21:50:49 listening on domain: .
2015/09/14 21:50:49 listening on domain: swarm.
2015/09/14 21:50:49 listening on domain: docker.
2015/09/14 21:50:49 listening on domain: local.

...

$ docker run -it debian:jessie bash

root@69967c3e5179:/# ping redis.swarm
PING redis.swarm (192.168.99.101): 56 data bytes
64 bytes from 192.168.99.101: icmp_seq=0 ttl=63 time=0.001 ms

root@69967c3e5179:/# ping dns.swarm
PING dns.swarm (192.168.99.100): 56 data bytes
64 bytes from 192.168.99.100: icmp_seq=0 ttl=64 time=0.030 ms

root@69967c3e5179:/# ping dns.docker
PING dns.docker (172.17.0.85): 56 data bytes
64 bytes from 172.17.0.85: icmp_seq=0 ttl=64 time=0.076 ms

rawdns's People

Contributors

maxpeal avatar paultag avatar tianon avatar timwolla avatar tombee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rawdns's Issues

Allow filtering the IP addresses that RawDNS returns for a given container

I have some containers that have a frontend and backend network defined. Currently, if I perform a name resolution on those containers I am receiving both addresses.

We should consider a config.json option that excludes specifically labeled OR named networks from being advertised over DNS.

For arguments sake, we'll consider the containers db, redis, and app as created by the following docker-compose file:

networks:
  frontend
  backend:
    internal: true

services:
  db:
    image: mariadb
    networks:
      - backend
  redis:
    image: redis
    networks:
     - backend
  app:
    image: my_custom_app
    networks:
      - backend
      - frontend
    depends_on:
      - db
      - redis

If we dig <rawdns_container> app.tld then I should only receive the frontend IP address.

We can achieve this through some configuration option like:

{
	"docker.lab.local." {
		"type": "containers",
		"exclude": {
			"labels": [ "DO_NOT_RESOLVE" ]
			"names": [ "backend" ]
		}
		"socket": "unix:////var/run/docker.sock"
	},
	"lab.local.": {
		"type": "forwarding",
		"nameservers": [ "192.168.1.250" ]
	}
	".": {
			"type": "forwarding",
			"nameservers": [ "208.67.220.220" ]
	}
}

The way you would read this is:

  1. Resolve *.docker.label.local via the Docker API
  2. If a container has a network labeled DO_NOT_RESOLVE, then don't return IPs with that network
  3. If a container has a network named backend, then don't return IPs associated with that network

So if I try a dig <rawdns_container> app.tld then I would only receive the frontend IP.

"type": "static"

Here's an example configuration blurb of what I've got in mind:

{
    "http.debian.net.": {
        "type": "static",
        "CNAME": [ "apt-cacher-ng.docker" ]
    },
    "my-new-tld.": {
        "type": "static",
        "A": [ "1.2.3.4", "5.6.7.8" ],
        "AAAA": [ "::1", "::2" ],
        "TXT": [ "lolololol" ]
    }
}

--net=host containers

If a container is set to --net=host, it gets no IP, which is obviously less than helpful for us. We should be able to figure out something for this case, but exactly what would be "correct" here is debatable.

DRY configuration (aliases)

I've got a lot of 100% duplicated blocks in my configuration (because I MITM several .deb mirrors to my local apt-cacher-ng instance, exactly like https://github.com/tianon/rawdns/blob/b2cec4eeff1377afdfd8c90e5a4716eb82370a09/hacks/apt-cacher-ng.md, so whatever gets implemented here should be reflected there), so it'd be nice to have some way to say something like "configuration for this new host should be copied from that other host".

I see two main ways to implement this:

{
	"host1.": {
		...
	},
	"host2.": "host1."
}

Main pros: simple for users to write
Main cons: annoying to implement (StringOrDomainConfig, etc), inflexible for later enhancement

{
	"host1.": {
		...
	},
	"host2.": {
		"copy": "host1.",
		...
	}
}

(or "type": "copy", but I'm not sure I like that -- being able to change even the "type" of what we've copied from seems fun -- maybe "merge": "host1." is better to make it clear what's happening here)

Main pros: flexible, saves code from needing complex unmarshalling for StringOrDomainConfig
Main cons: slightly complex "merging" behavior

One thing to decide would be whether "cnames": [ "1.2.3.4" ] merged into "cnames": [ "5.6.7.8" ] becomes [ "5.6.7.8" ] or [ "1.2.3.4", "5.6.7.8" ].

fd leak while connecting to docker on pf_local socket

After deploying rawdns (version 1.2~ds1-1 from debian) in a small sized docker environment - i got the following errors, just a fetr a few minutes of operation:

rawdns[34447]: 2015/09/18 13:03:08 error: failed to lookup container "test": failed HTTP request: Get http://unix-socket/v1.14/containers/rabbitmq/json: dial unix /var/run/docker.sock: too many open files

lsof shows that rawdns has consumed all the 1021 fd's.
The following small patch fixes the issue for me:

diff --git a/src/cmd/rawdns/docker.go b/src/cmd/rawdns/docker.go
index 94c3140..7d763a5 100644
--- a/src/cmd/rawdns/docker.go
+++ b/src/cmd/rawdns/docker.go
@@ -58,6 +58,7 @@ func httpClient(u *url.URL) *http.Client {
                transport.Dial = func(proto, addr string) (net.Conn, error) {
                        return net.Dial("unix", path)
                }
+               transport.DisableKeepAlives = true
                u.Scheme = "http"
                u.Host = "unix-socket"
                u.Path = ""

Update of the Debian package

I noticed that the newest packaged version is 1.6 (in Stretch, Buster and Sid), would it be possible to update the package to version 1.7?

ANY queries

If the question type is ANY, all RRs should be in Answer, not Extra, regardless of their type.

CoreDNS?

As I've mentioned now in #25 (comment), I went to a talk about CoreDNS, specifically around flexibility (and doing "horrible" things with it), and I was really impressed.

I think it makes sense to see what it would take to replicate rawdns via CoreDNS (if anything -- maybe the fundamentals are already there!), since that would offer much more flexibility in the long run.

high memory usage

Using this in a project where rawdns gets 2-3 queries a second.

After around 24hrs I have observed rawdns and the docker daemon using several GB of memory. DNS lookups still work, and I can't find anything unusual in either docker or rawdns logs.

Not sure what other details or debug information I can provide.

System: Ubuntu 14.04, Docker 1.3.2, public rawdns image (6320427debfe)

IPv6 AAAA support coming?

Hi,

I noticed this TODO (

//dnsAppend(q, m, &dns.AAAA{AAAA: net.ParseIP(container.NetworkSettings.Ipv6AddressesAsMultipleAnswerEntries)})
// TODO IPv6 support (when Docker itself has such a thing...)
):

// TODO IPv6 support (when Docker itself has such a thing...)

Docker does support IPv6 (https://docs.docker.com/engine/userguide/networking/default_network/ipv6/) and, thusly, it would be great if this DNS implementation could serve AAAA records. I can also see that there is ".NetworkSettings.GlobalIPv6Address" provided in the response from [docker]/containers/web/json in ApiVersion 1.22 (and possibly before that version as well) that could be returned by this implementation.

disable dnsmasq and use --dns

In ubuntu 14.04 desktop I need to disable dnsmasq by commenting "dns=dnsmasq" in /etc/NetworkManager/NetworkManager.conf

I think that the readme should explain that other containers that want to access the rawdns service need to pass the docker0 host ip
--dns

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.