英文:
Dockerfile fails to download module
问题
我有以下的代码结构:
notificator
| Dockerfile
| go.mod
| go.sum
| notificator.pb.go
|
+-- cmd
| .go files
+-- pkg
.go files
以下的Dockerfile可以成功构建:
FROM golang
WORKDIR /notificator
COPY . .
RUN go get -t -v ./...
RUN mkdir bin
RUN go build -o bin ././...
RUN chmod +x bin/cmd
ENTRYPOINT ["./bin/cmd"]
但是当我重构它为:
FROM golang
WORKDIR /notificator
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN mkdir bin
RUN go build -o bin ././...
RUN chmod +x bin/cmd
ENTRYPOINT ["./bin/cmd"]
go mod download 返回以下错误:
#12 0.816 /go/pkg/mod/github.com/go-kit/kit@v0.12.0/sd/etcd/client.go:13:2: missing go.sum entry for module providing package go.etcd.io/etcd/client/v2 (imported by github.com/go-kit/kit/sd/etcd); to add:
#12 0.816 go get github.com/go-kit/kit/sd/etcd@v0.12.0
但是 go.sum 包含了:
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lLS/oTh0=
我不明白为什么这两个文件的行为不同?
英文:
I have the following code structure
notificator
| Dockerfile
| go.mod
| go.sum
| notificator.pb.go
|
+-- cmd
| .go files
+-- pkg
.go files
The following Dockerfile builds successfully:
FROM golang
WORKDIR /notificator
COPY . .
RUN go get -t -v ./...
RUN mkdir bin
RUN go build -o bin ././...
RUN chmod +x bin/cmd
ENTRYPOINT [ "./bin/cmd" ]
But when I refactor it to:
FROM golang
WORKDIR /notificator
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN mkdir bin
RUN go build -o bin ././...
RUN chmod +x bin/cmd
ENTRYPOINT [ "./bin/cmd" ]
go mod download returns the following error:
#12 0.816 /go/pkg/mod/github.com/go-kit/kit@v0.12.0/sd/etcd/client.go:13:2: missing go.sum entry for module providing package go.etcd.io/etcd/client/v2 (imported by github.com/go-kit/kit/sd/etcd); to add:
#12 0.816 go get github.com/go-kit/kit/sd/etcd@v0.12.0
BUT go.sum contains:
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lLS/oTh0=
I don't understand why the two files behave differently?
答案1
得分: 1
运行 go mod tidy
解决了这个问题。
英文:
Running go mod tidy
fixed the issue
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论