duanlie4621 2019-05-05 07:52
浏览 151
已采纳

在192.168.65.1:53上查找google.com:无法解组DNS邮件

I have been with getting my docker image to issue srv record queries. It seems the golang guys broke the existing behavior by disregarding malformed records. I heard there was a fix, but I keep trying newer versions of ubuntu/alpine linux and nothing seems to make a difference. I cannot downgrade to golang 1.10. Is there something I'm doing wrong here? like screwing up my docker file? how ca I make this code actually work in my container? My code:

package main

import (
    "fmt"
    "net"
)

func main() {
    net.DefaultResolver.PreferGo=true
    cname, srvs, err := net.LookupSRV("xmpp-server", "tcp", "google.com")
    if err != nil {
        panic(err)
    }

    fmt.Printf("
cname: %s 

", cname)

    for _, srv := range srvs {
        fmt.Printf("%v:%v:%d:%d
", srv.Target, srv.Port, srv.Priority, srv.Weight)
    }

    // cname: _xmpp-server._tcp.google.com.
    //
    // xmpp-server.l.google.com.:5269:5:0
    // alt2.xmpp-server.l.google.com.:5269:20:0
    // alt1.xmpp-server.l.google.com.:5269:20:0
    // alt4.xmpp-server.l.google.com.:5269:20:0
    // alt3.xmpp-server.l.google.com.:5269:20:0
}

My error:

panic: lookup google.com on 192.168.65.1:53: cannot unmarshal DNS message

goroutine 1 [running]:
main.main()
    /app/run_stuff.go:12 +0x322
exit status 2

my docker file:

FROM golang:1.12
RUN mkdir /app 
RUN uname -a
RUN go version
WORKDIR /app
COPY . /app/
CMD ["go","run","run_stuff.go"]
  • 写回答

1条回答 默认 最新

  • douweng3564 2019-05-05 18:11
    关注

    It's not really a Go issue. Running go run run_stuff.go on my mac yields the result you're expecting

    $ go run run_stuff.go 
    
    cname: _xmpp-server._tcp.google.com. 
    
    xmpp-server.l.google.com.:5269:5:0
    alt2.xmpp-server.l.google.com.:5269:20:0
    alt4.xmpp-server.l.google.com.:5269:20:0
    alt1.xmpp-server.l.google.com.:5269:20:0
    alt3.xmpp-server.l.google.com.:5269:20:0
    

    The issue likely has to do with your DNS settings in Docker. Using the exact same code and Dockerfile as you posted above, I ran the command docker build -t test . && docker run --rm -it --dns 8.8.8.8 test which builds and runs the container. The difference being that I set the --dns flag (see the Docker docs for details). The result being:

    $ docker build -t test . && docker run --rm -it --dns 8.8.8.8  test  
    Sending build context to Docker daemon  27.14kB
    Step 1/7 : FROM golang:1.12.4
     ---> b860ab44e93e
    Step 2/7 : RUN mkdir /app
     ---> Using cache
     ---> 2a339a5e5fde
    Step 3/7 : RUN uname -a
     ---> Using cache
     ---> dac4362453e6
    Step 4/7 : RUN go version
     ---> Using cache
     ---> ae654c1c4aa6
    Step 5/7 : WORKDIR /app
     ---> Using cache
     ---> db3c82038173
    Step 6/7 : COPY . /app/
     ---> 9dba317a267d
    Step 7/7 : CMD ["go","run","run_stuff.go"]
     ---> Running in 2ea6b38869f1
    Removing intermediate container 2ea6b38869f1
     ---> 0a0f817b51bb
    Successfully built 0a0f817b51bb
    Successfully tagged test:latest
    
    cname: _xmpp-server._tcp.google.com. 
    
    xmpp-server.l.google.com.:5269:5:0
    alt4.xmpp-server.l.google.com.:5269:20:0
    alt3.xmpp-server.l.google.com.:5269:20:0
    alt1.xmpp-server.l.google.com.:5269:20:0
    alt2.xmpp-server.l.google.com.:5269:20:0
    

    The default DNS server (192.168.65.1, usually set in /etc/resolv.conf) isn't capable of resolving the query. You could update the DNS settings for your host system, or add the --dns flag to make your code work properly in a Docker container.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法