From 170003bf801d14b435c32697f7a871608509ca6d Mon Sep 17 00:00:00 2001 From: Lionel Touati Date: Wed, 25 Mar 2015 09:18:23 +0100 Subject: [PATCH 1/2] Add build file + support multiple domains --- build.sh | 2 ++ dns.go | 6 ++++-- go_build.sh | 5 +++++ main.go | 5 +++-- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100755 build.sh create mode 100755 go_build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a0b4bba --- /dev/null +++ b/build.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker run -ti --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang:1.3 /usr/src/myapp/go_build.sh diff --git a/dns.go b/dns.go index 4e0e3bc..e722acd 100644 --- a/dns.go +++ b/dns.go @@ -10,7 +10,7 @@ import ( type DNS struct { bind string port int - domain string + domains []string recursors []string cache Cache } @@ -34,7 +34,9 @@ func (s *DNS) Run() { Handler: mux, } - mux.HandleFunc(s.domain, s.handleDNSInternal) + for _, domain := range s.domains { + mux.HandleFunc(domain, s.handleDNSInternal) + } mux.HandleFunc("in-addr.arpa.", s.handleReverseDNSLookup) mux.HandleFunc(".", s.handleDNSExternal) diff --git a/go_build.sh b/go_build.sh new file mode 100755 index 0000000..7f87200 --- /dev/null +++ b/go_build.sh @@ -0,0 +1,5 @@ +#!/bin/bash +go get github.com/fsouza/go-dockerclient +go get github.com/miekg/dns +go build -o docker-spy *.go +strip docker-spy diff --git a/main.go b/main.go index 7189453..a33cbb4 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "os" "os/signal" "strconv" + "strings" dockerApi "github.com/fsouza/go-dockerclient" ) @@ -13,7 +14,7 @@ import ( var dnsBind = flag.String("dns-bind", getopt("DNS_BIND", "0.0.0.0"), "Bind address for the DNS server") var dnsPort = flag.String("dns-port", getopt("DNS_PORT", "53"), "Port for the DNS server") var dnsRecursor = flag.String("dns-recursor", getopt("DNS_RECURSOR", ""), "DNS recursor for non-local addresses") -var dnsDomain = flag.String("dns-domain", getopt("DNS_DOMAIN", "localdomain"), "The domain that Docker-spy should consider local") +var dnsDomains = flag.String("dns-domains", getopt("DNS_DOMAINS", "localdomain"), "The domains ( coma separated ) that Docker-spy should consider local") var dockerHost = flag.String("docker-host", getopt("DOCKER_HOST", "unix:///var/run/docker.sock"), "Address for the Docker daemon") func getopt(name, def string) string { @@ -38,7 +39,7 @@ func main() { bind: *dnsBind, port: port, recursors: []string{*dnsRecursor + ":53"}, - domain: *dnsDomain + ".", + domains: strings.Split(*dnsDomains,","), } server.Run() From 06210460f8315fabd9b825d5392de4a51fa9a53e Mon Sep 17 00:00:00 2001 From: Lionel Touati Date: Wed, 25 Mar 2015 09:33:18 +0100 Subject: [PATCH 2/2] Forgot . --- dns.go | 6 ++++-- readme.md | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dns.go b/dns.go index e722acd..8be0cd5 100644 --- a/dns.go +++ b/dns.go @@ -35,8 +35,10 @@ func (s *DNS) Run() { } for _, domain := range s.domains { - mux.HandleFunc(domain, s.handleDNSInternal) - } + domain = domain + "." + log.Printf("Starting resolver for domain %s",domain) + mux.HandleFunc(domain, s.handleDNSInternal) + } mux.HandleFunc("in-addr.arpa.", s.handleReverseDNSLookup) mux.HandleFunc(".", s.handleDNSExternal) diff --git a/readme.md b/readme.md index 3298b0e..2907b86 100644 --- a/readme.md +++ b/readme.md @@ -15,7 +15,7 @@ Docker-spy can be configured through a number of environment variables: * DNS_BIND: the address that the DNS server will bind to in the container. Defaults to '0.0.0.0'. * DNS_PORT: the port on which the DNS server will be reachable (tcp/udp). Defaults to '53' * DNS_RECURSOR: the recursor to use when DNS requests are made to non-local addresses. Defaults to '8.8.8.8' from the Dockerfile -* DNS_DOMAIN: the domain that docker-spy should consider local and keep records for. Defaults to 'localdomain' +* DNS_DOMAINS: the domains ( coma separated ) that docker-spy should consider local and keep records for. Defaults to 'localdomain' * DOCKER_HOST: the location of the Docker daemon. Defaults to the DOCKER_HOST environment variable or, if the DOCKER_HOST environment variable is not set, unix:///var/run/docker.sock. Setting this explicitly allows you to override the location. ### DNS Forwarding