diff --git a/README.md b/README.md index 9681200..4ab4193 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ A simple DNS server to resolve names of local Docker containers. +`Added by Schinti95:` IP Address lookup when using docker networks. + `resolvable` is intended to run in a Docker container: docker run -d \ diff --git a/main.go b/main.go index 3b66cc7..38cc3eb 100644 --- a/main.go +++ b/main.go @@ -101,6 +101,12 @@ func registerContainers(docker *dockerapi.Client, events chan *dockerapi.APIEven } continue } + for key, value := range container.NetworkSettings.Networks { + if value.IPAddress != "" { + log.Println("Found Container with IP: ", value.IPAddress, "from Network: ", key) + return net.ParseIP(value.IPAddress), nil + } + } return nil, fmt.Errorf("unknown network mode", container.HostConfig.NetworkMode) } @@ -229,7 +235,7 @@ func run() error { } defer dnsResolver.Close() - localDomain := "docker" + localDomain := "internal" dnsResolver.AddUpstream(localDomain, nil, 0, localDomain) resolvConfig, err := dns.ClientConfigFromFile("/etc/resolv.conf")