Dockerfile下载模块失败。

huangapple go评论115阅读模式
英文:

Dockerfile fails to download module

问题

我有以下的代码结构:

  1. notificator
  2. | Dockerfile
  3. | go.mod
  4. | go.sum
  5. | notificator.pb.go
  6. |
  7. +-- cmd
  8. | .go files
  9. +-- pkg
  10. .go files

以下的Dockerfile可以成功构建:

  1. FROM golang
  2. WORKDIR /notificator
  3. COPY . .
  4. RUN go get -t -v ./...
  5. RUN mkdir bin
  6. RUN go build -o bin ././...
  7. RUN chmod +x bin/cmd
  8. ENTRYPOINT ["./bin/cmd"]

但是当我重构它为:

  1. FROM golang
  2. WORKDIR /notificator
  3. COPY go.mod .
  4. COPY go.sum .
  5. RUN go mod download
  6. COPY . .
  7. RUN mkdir bin
  8. RUN go build -o bin ././...
  9. RUN chmod +x bin/cmd
  10. ENTRYPOINT ["./bin/cmd"]

go mod download 返回以下错误:

  1. #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:
  2. #12 0.816 go get github.com/go-kit/kit/sd/etcd@v0.12.0

但是 go.sum 包含了:

  1. go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
  2. go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
  3. go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
  4. go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lLS/oTh0=

我不明白为什么这两个文件的行为不同?

英文:

I have the following code structure

  1. notificator
  2. | Dockerfile
  3. | go.mod
  4. | go.sum
  5. | notificator.pb.go
  6. |
  7. +-- cmd
  8. | .go files
  9. +-- pkg
  10. .go files

The following Dockerfile builds successfully:

  1. FROM golang
  2. WORKDIR /notificator
  3. COPY . .
  4. RUN go get -t -v ./...
  5. RUN mkdir bin
  6. RUN go build -o bin ././...
  7. RUN chmod +x bin/cmd
  8. ENTRYPOINT [ "./bin/cmd" ]

But when I refactor it to:

  1. FROM golang
  2. WORKDIR /notificator
  3. COPY go.mod .
  4. COPY go.sum .
  5. RUN go mod download
  6. COPY . .
  7. RUN mkdir bin
  8. RUN go build -o bin ././...
  9. RUN chmod +x bin/cmd
  10. ENTRYPOINT [ "./bin/cmd" ]

go mod download returns the following error:

  1. #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:
  2. #12 0.816 go get github.com/go-kit/kit/sd/etcd@v0.12.0

BUT go.sum contains:

  1. go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
  2. go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
  3. go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
  4. 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

huangapple
  • 本文由 发表于 2022年1月12日 20:11:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/70681347.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定