You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Go程序Dockerfile构建失败:跨环境差异问题排查与解决

Docker构建DNS解析失败问题解决

问题现象

同一份Dockerfile可在本地机器及一台远程服务器上成功构建,但在办公室的另一台远程服务器执行构建时出现如下错误:

remote: #9 [builder 5/5] RUN --mount=type=cache,target=/root/.cache/go-build   GOPROXY=direct go mod download &&   go generate ./... &&   go build -o sponsorship cmd/main.go
remote: #9 0.473 go: ariga.io/atlas@v0.9.1-0.20230119145809-92243f7c55cb: unrecognized import path "ariga.io/atlas": https fetch: Get "https://ariga.io/atlas?go-get=1": dial tcp: lookup ariga.io on [fe80::1%wlp0s20f3]:53: dial udp [fe80::1%wlp0s20f3]:53: connect: invalid argument
remote: #9 ERROR: process "/bin/sh -c GOPROXY=direct go mod download &&   go generate ./... &&   go build -o sponsorship cmd/main.go" did not complete successfully: exit code: 1
remote: ------
remote:  > [builder 5/5] RUN --mount=type=cache,target=/root/.cache/go-build   GOPROXY=direct go mod download &&   go generate ./... &&   go build -o sponsorship cmd/main.go:
remote: #9 0.473 go: ariga.io/atlas@v0.9.1-0.20230119145809-92243f7c55cb: unrecognized import path "ariga.io/atlas": https fetch: Get "https://ariga.io/atlas?go-get=1": dial tcp: lookup ariga.io on [fe80::1%wlp0s20f3]:53: dial udp [fe80::1%wlp0s20f3]:53: connect: invalid argument
remote: ------
remote: time="2023-03-06T17:14:09+03:00" level=warning msg="buildx: failed to read current commit information with git rev-parse --is-inside-work-tree"
remote: failed to solve: process "/bin/sh -c GOPROXY=direct go mod download &&   go generate ./... &&   go build -o sponsorship cmd/main.go" did not complete successfully: exit code: 1

排查过程

  • 尝试设置环境变量GOPROXY=direct,问题未解决
  • 办公室内其他服务器或笔记本执行Docker构建均正常,排除Dockerfile本身及依赖源的问题

解决方法

编辑目标服务器的/etc/networking文件,添加有效的域名服务器配置后,构建成功。感谢@erik258提供的解决方案。


内容的提问来源于stack exchange,提问作者Alexander Ushakov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 05:10:22