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.

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

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题