Docker部署golang项目 出现 ip: i/o timeout,需要在dockerfile中增加配置,ENV GOPROXY https://goproxy.cn

文章讲述了在使用Docker构建Golang项目时遇到`i/otimeout`错误,解决方法是通过在Dockerfile中设置`ENVGOPROXY`为`https://goproxy.cn`。同时提到,单独使用`goenv`设置GOPROXY仅对`gobuild`有效,而Docker构建时需额外设置`GO111MODULE`。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

bug:

#0 90.38 go: github.com/bytedance/sonic@v1.10.2: Get "https://proxy.golang.org/github.com/bytedance/sonic/@v/v1.10.2.mod": dial tcp 142.251.42.241:443: i/o timeout
------
Dockerfile:6
--------------------
   4 |     COPY . .
   5 |
   6 | >>> RUN go build main.go
   7 |
   8 |     EXPOSE 8080
--------------------
ERROR: failed to solve: process "/bin/sh -c go build main.go" did not complete successfully: exit code: 1

解决办法:需要在dockerfile中增加配置,ENV GOPROXY https://goproxy.cn 

在终端运行go env -w GOPROXY=https://goproxy.cn是只能决绝go build;docker build go时此方法无法解决;本地go build或go run时出现i/o timeout bug可以在终端运行:

$ go env -w GO111MODULE=on
$ go env -w GOPROXY=https://goproxy.cn,direct
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值