在RancherDesktop集群中进行Docker构建时,go mod download出现了无效的引用错误。

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

Lame referral error on go mod download during docker build in RancherDesktop cluster

问题

我在执行Docker构建过程中遇到了一个错误,错误发生在下载Golang依赖项的"RUN go mod download"行。通常会出现许多类似以下的引用错误:

错误信息:

...
 => CACHED [builder 4/7] COPY go.sum go.mod Makefile /app/                                                                                              0.0s
 => ERROR [builder 5/7] RUN go mod download                                                                                                            18.5s
------
 > [builder 5/7] RUN go mod download:
#12 17.98 go mod download: github.com/aws/aws-sdk-go@v1.44.13: Get "https://storage.googleapis.com/proxy-golang-org-prod/6d16f241873ba42e-github.com:aws:aws-sdk-go-v1.44.13.zip?Expires=x&GoogleAccessId=gcs-urlsigner-prod%40golang-modproxy.iam.gserviceaccount.com&Signature=x": dial tcp: lookup storage.googleapis.com on 192.168.x.x:53: lame referral
...
------
executor failed running [/bin/sh -c go mod download]: exit code: 1

有时候Docker构建会成功,但几乎总是在进行go mod download时的30秒后失败。

我是在企业VPN内部。我可以直接从我的Mac上运行"go mod download"命令轻松地拉取这些依赖项,但是在Docker构建过程中经常遇到此错误。我的队友们在不同地区尝试构建时也遇到类似的问题。如果我们需要配置Docker代理或添加known_hosts,希望能提供具体的示例。

以下是Dockerfile的内容:

FROM golang:1.16.4-buster AS builder
ENV GOOS=linux GOARCH=amd64 CGO_ENABLED=1 GOPRIVATE="github.com/x"
ARG GITHUB_ACCESS_TOKEN

RUN mkdir -p -m 0600 /root/.ssh && \
  ssh-keyscan github.com >> ~/.ssh/known_hosts && \
  git config --global url."https://${GITHUB_ACCESS_TOKEN}:@github.com/".insteadOf "https://github.com/"

# separate for better caching purpose
WORKDIR /app
COPY go.sum go.mod Makefile /app/
RUN go mod download
COPY . .
RUN make install && make build
...
英文:

I encounter an error during my docker build on the "RUN go mod download" line that is downloading Golang dependencies. It usually fails with numerous lame referral errors like the following:

Error:

...
 => CACHED [builder 4/7] COPY go.sum go.mod Makefile /app/                                                                                              0.0s
 => ERROR [builder 5/7] RUN go mod download                                                                                                            18.5s
------
 > [builder 5/7] RUN go mod download:
#12 17.98 go mod download: github.com/aws/aws-sdk-go@v1.44.13: Get "https://storage.googleapis.com/proxy-golang-org-prod/6d16f241873ba42e-github.com:aws:aws-sdk-go-v1.44.13.zip?Expires=x&GoogleAccessId=gcs-urlsigner-prod%40golang-modproxy.iam.gserviceaccount.com&Signature=x": dial tcp: lookup storage.googleapis.com on 192.168.x.x:53: lame referral
...
------
executor failed running [/bin/sh -c go mod download]: exit code: 1

Every once in a while the docker build will work, but it almost always fails after 30s during this go mod download.

I'm within a corporate VPN. I can pull these dependencies directly from my Mac easily by directly running "go mod download", but docker build encounters this error very often. My teammates experience similar issues when they try to build as well from different regions. If we need to configure a docker proxy or add known_hosts, specific examples would be appreciated.

Dockerfile:

FROM golang:1.16.4-buster AS builder
ENV GOOS=linux GOARCH=amd64 CGO_ENABLED=1 GOPRIVATE="github.com/x"
ARG GITHUB_ACCESS_TOKEN

RUN mkdir -p -m 0600 /root/.ssh && \
  ssh-keyscan github.com >> ~/.ssh/known_hosts && \
  git config --global url."https://${GITHUB_ACCESS_TOKEN}:@github.com/".insteadOf "https://github.com/"

# separate for better caching purpose
WORKDIR /app
COPY go.sum go.mod Makefile /app/
RUN go mod download
COPY . .
RUN make install && make build
...

答案1

得分: 1

我还不确定这是否是一个持久的解决方法,但是我通过以下比较冗长的过程解决了今天的问题:

  1. minikube stop(minikube 连接到我的本地 RancherDesktop 集群)
  2. 重新启动 RancherDesktop(同时更新它)
  3. minikube start - 这告诉我 docker 的磁盘空间不足
  4. minikube delete(可能有点过头了,minikube ssh -- docker system prune 可能也可以解决)
  5. minikube start
  6. eval $(minikube -p minikube docker-env)
  7. 构建和启动我的服务(使用 Skaffold 利用 Docker 构建和通过 minikube 使用 Helm 部署)

不要提供无用的参考!

英文:

I'm not sure yet if this is a consistent fix, but I was able to resolve this for today via the following unfortunately long process:

  1. minikube stop (minikube connects to my local RancherDesktop cluster)
  2. re-start RancherDesktop (also updated it)
  3. minikube start - this informed me that docker was out of disk space
  4. minikube delete (maybe overkill, minikube ssh -- docker system prune might have worked)
  5. minikube start
  6. eval $(minikube -p minikube docker-env)
  7. build and start my service/s (using Skaffold which utilizes Docker to build and Helm via minikube to deploy)

No lame referrals!

huangapple
  • 本文由 发表于 2022年10月13日 00:24:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/74045107.html
匿名

发表评论

匿名网友

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

确定