7

I'm trying to build my go project in the docker container.

Here is the dockerfile:

FROM golang:1.12.9 as builder

ENV GO111MODULE=on
WORKDIR /app

COPY go.mod .
COPY go.sum .

RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o encashment


FROM scratch
COPY --from=builder /app/encashment /encashment/
EXPOSE 8080
ENTRYPOINT ["/app/encashment"]

I have only one dependency in go.mod:

require github.com/gorilla/mux v1.7.3

If I delete gorilla/mux locally and call go mod download, everyhing works fine. But when I call docker build . it returns

go: finding github.com/gorilla/mux v1.7.3
go: github.com/gorilla/mux@v1.7.3: unknown revision v1.7.3
go: error loading module requirements

How to make this work?
UPD: Here is the piece of tcpdump output:

19:00:00.220102 IP 172.17.0.2.43627 > dns.google.domain: 15472+ A? github.com. (28)
19:00:00.220115 IP 172.17.0.2.43627 > dns.google.domain: 64629+ AAAA? github.com. (28)
19:00:02.969391 IP 172.17.0.1.38261 > 239.255.255.250.1900: UDP, length 172
19:00:03.971322 IP 172.17.0.1.38261 > 239.255.255.250.1900: UDP, length 172
19:00:04.971794 IP 172.17.0.1.38261 > 239.255.255.250.1900: UDP, length 172
19:00:05.221952 IP 172.17.0.2.40395 > dns.google.domain: 15472+ A? github.com. (28)
19:00:05.221992 IP 172.17.0.2.40395 > dns.google.domain: 64629+ AAAA? github.com. (28)
19:00:05.970002 IP 172.17.0.1.mdns > 224.0.0.251.mdns: 0 PTR (QM)? _googlecast._tcp.local. (40)
19:00:05.970263 IP 172.17.0.1.mdns > 224.0.0.251.mdns: 0 PTR (QM)? _googlecast._tcp.local. (40)
19:00:05.972573 IP 172.17.0.1.38261 > 239.255.255.250.1900: UDP, length 172
19:00:06.971288 IP 172.17.0.1.mdns > 224.0.0.251.mdns: 0 PTR (QM)? _googlecast._tcp.local. (40)
19:00:06.971446 IP 172.17.0.1.mdns > 224.0.0.251.mdns: 0 PTR (QM)? _googlecast._tcp.local. (40)
19:00:08.972581 IP 172.17.0.1.mdns > 224.0.0.251.mdns: 0 PTR (QM)? _googlecast._tcp.local. (40)
19:00:08.972736 IP 172.17.0.1.mdns > 224.0.0.251.mdns: 0 PTR (QM)? _googlecast._tcp.local. (40)
19:00:10.224125 IP 172.17.0.2.43627 > dns.google.domain: 15472+ A? github.com. (28)
19:00:10.224171 IP 172.17.0.2.43627 > dns.google.domain: 64629+ AAAA? github.com. (28)

Rob Lucci
  • 99
  • 1
  • 5
  • 1
    Tried to replicate but it worked on my Docker build: > Step 6/12 : RUN go mod download > go: finding github.com/gorilla/mux v1.7.3 > Step 7/12 : COPY . . Are you sure your Docker Engine has internet access denied due to proxy settings? – prometherion Aug 27 '19 at 15:17
  • @prometherion I don't know how to check this for sure, but I've added `tcpdump -i docker0` output – Rob Lucci Aug 27 '19 at 16:06
  • Thanks for the `go mod download` after only copying .mod and .sum I was re-fetching deps like crazy. Now the cache works. – Karl Pokus May 09 '20 at 19:23

1 Answers1

3

Well, thanks to @prometherion The problem was in the absence of internet access from within of docker container. This SO answer worked for me. Guess that I should create an issue in golang repo and ask to rework this error message.

Rob Lucci
  • 99
  • 1
  • 5