简体   繁体   English

如何在docker中构建go模块?

[英]How to build go modules in docker?

I'm trying to build my go project in the docker container. 我正在尝试在docker容器中构建我的go项目。

Here is the dockerfile: 这是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: 我在go.mod中只有一个依赖:

require github.com/gorilla/mux v1.7.3

If I delete gorilla/mux locally and call go mod download , everyhing works fine. 如果我在本地删除gorilla/mux并调用go mod download ,则可以正常运行。 But when I call docker build . 但是当我打电话给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: UPD:这是tcpdump输出:

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)

Well, thanks to @prometherion The problem was in the absence of internet access from within of docker container. 好吧,感谢@prometherion问题是在docker容器内没有互联网访问。 This SO answer worked for me. 这个SO答案对我有用。 Guess that I should create an issue in golang repo and ask to rework this error message. 猜猜我应该在golang repo中创建一个问题并要求重做这个错误信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM