2

I am writing a small app that should run in a docker container, and should interact with other docker container via its hostname.

I am trying to get the IP Address of the server using net.LookupHost, but I am always getting 127.0.53.53

The weird thing is that I can get the right IP Address using dns tools like dig from the same container. It only does not work from the go program.

Below is the section from my code where I get the IP Address.

zk_server_ips, err := net.LookupHost("zookeeper")
addrs, err := net.LookupIP("testserver")
if err != nil {
    fmt.Fprintf(w, "Failed to lookup ip address for testserver")
    return
}
for _, addr := range addrs {
if ipv4 := addr.To4(); ipv4 != nil {
    fmt.Fprintf(w, "IPv4: %s", ipv4)
}

I have read a lot that 127.0.53.53 is the way ICANN is telling me that there is something wrong with dsn setup, but I do not know why is it working with dig and drill and not from the go code. !

Also what is the right way to setup the docker containers to resolve hostnames?

The containers are running on Alpine linux image.

Below is my resolv.conf in the container:

search fritz.box
nameserver 127.0.0.11
options ndots:0
4
  • What does your resolv.conf look like. As you are asking for bare host names it could be that the resolver is taking on your domain name?
    – Doon
    Dec 12, 2016 at 22:48
  • search fritz.box nameserver 127.0.0.11 options ndots:0 Dec 12, 2016 at 22:56
  • 1
    do you have something like pow installed? or does docker intercept.
    – Doon
    Dec 12, 2016 at 23:04
  • @Doon No, I don't have pow installed. Just bare alpine image. Dec 12, 2016 at 23:07

2 Answers 2

1

I've run into the same issue when using Telegraf.

Unfortunately I don't know the root cause, but I was able to work around the issue by setting --dns-search=. when using docker run or by setting dns_search: . in Docker Compose v1 yaml files:

telegraf:
  image: telegraf:1.2.1-alpine
  dns_search: .
  volumes:
    - ./telegraf.conf:/etc/telegraf/telegraf.conf:ro

See the Docker DNS documentation for details about the --dns-search switch.

0

.box is a real TLD. Don't use it for internal systems.

If you need to give hostnames to local systems, use the .local TLD, which is reserved for this purpose.

1
  • Sorry for my late response. The problem is that this is set by router dhcp server, which I have to find a way to change it as there is no where in the router interface to do it. But again why is it working from the dns tools and not from gethostbyname? Dec 16, 2016 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.