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