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/[email protected]: 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)
tcpdump -i docker0
output – Endolymphgo mod download
after only copying .mod and .sum I was re-fetching deps like crazy. Now the cache works. – Shantel