golang net.LookupHost in docker container return

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

  • Java in python3-onbuild docker
  • How to run a Windows GUI application from a Windows VM on a Docker installed on windows?
  • How to run a jar file using docker image?
  • Triggering docker run from another docker container
  • Cannot Access Docker Phpmyadmin via Port
  • Docker container restart in Docker Swarm Cluster
  • 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")
    for _, addr := range addrs {
    if ipv4 := addr.To4(); ipv4 != nil {
        fmt.Fprintf(w, "IPv4: %s", ipv4)

    I have read a lot that 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
    options ndots:0

  • When starting WAS 8.5 app server from a docker container getting 502 Bad Gateway error
  • Selenium server works with Docker on MacOS but not on Jenkins
  • “java.net.NoRouteToHostException: No route to host” between two Docker Containers
  • Docker-compose rails postgres
  • Docker cross compile for ARM without hard-float
  • Container technologies: docker, rkt, orchestration, kubernetes, GKE and AWS Container Service
  • 2 Solutions collect form web for “golang net.LookupHost in docker container return”

    .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.

    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:

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

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

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.