Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type DNS struct {
bind string
port int
domain string
domains []string
recursors []string
cache Cache
}
Expand All @@ -34,7 +34,11 @@ func (s *DNS) Run() {
Handler: mux,
}

mux.HandleFunc(s.domain, s.handleDNSInternal)
for _, domain := range s.domains {
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)

Expand Down
5 changes: 5 additions & 0 deletions go_build.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"os"
"os/signal"
"strconv"
"strings"

dockerApi "github.com/fsouza/go-dockerclient"
)

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 {
Expand All @@ -38,7 +39,7 @@ func main() {
bind: *dnsBind,
port: port,
recursors: []string{*dnsRecursor + ":53"},
domain: *dnsDomain + ".",
domains: strings.Split(*dnsDomains,","),
}

server.Run()
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down