doutian3010 2016-12-12 22:43
浏览 504

docker容器中的golang net.LookupHost返回127.0.53.53

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
  • 写回答

2条回答 默认 最新

  • dss67853 2016-12-12 23:32
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配