使用Docker时遇到了“golang.org/x/net/context/ctxhttp”包的超时问题。

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

Get package timeout with Docker - "golang.org/x/net/context/ctxhttp"

问题

我尝试使用Go的Docker镜像导入这个

根据该包的文档,运行的命令是:

 go get gopkg.in/olivere/elastic.v3

这个命令可以正常工作。

我需要在Docker镜像中执行相同的操作:

docker run -v $PWD:/temp -w /temp -e GOPATH=$PWD -e GOBIN=$PWD/bin golang:latest go get gopkg.in/olivere/elastic.v3

但是我遇到了以下错误:

> package golang.org/x/net/context: 无法识别的导入路径
> "golang.org/x/net/context" (https获取:获取
> https://golang.org/x/net/context?go-get=1: 拨号TCP:在192.168.65.1:53上查找golang.org
> 时发生错误:读取UDP 172.17.0.2:46904->192.168.65.1:53:I/O超时)
>
> package golang.org/x/net/context/ctxhttp: 无法识别的导入路径
> "golang.org/x/net/context/ctxhttp" (https获取:获取
> https://golang.org/x/net/context/ctxhttp?go-get=1: 拨号TCP:在192.168.65.1:53上查找golang.org
> 时发生错误:读取UDP 172.17.0.2:44687->192.168.65.1:53:I/O超时)

这是为什么呢?

英文:

I try to import this package using the go Docker image.

From the docs of the package, the command to run is:

 go get gopkg.in/olivere/elastic.v3

Works, fair enough.

I need to do the same with the docker image:

docker run -v $PWD:/temp -w /temp -e GOPATH=$PWD -e GOBIN=$PWD/bin golang:latest go get gopkg.in/olivere/elastic.v3

But I got the following error:

> package golang.org/x/net/context: unrecognized import path
> "golang.org/x/net/context" (https fetch: Get
> https://golang.org/x/net/context?go-get=1: dial tcp: lookup golang.org
> on 192.168.65.1:53: read udp 172.17.0.2:46904->192.168.65.1:53: i/o
> timeout)
>
> package golang.org/x/net/context/ctxhttp: unrecognized import
> path "golang.org/x/net/context/ctxhttp" (https fetch: Get
> https://golang.org/x/net/context/ctxhttp?go-get=1: dial tcp: lookup
> golang.org on 192.168.65.1:53: read udp
> 172.17.0.2:44687->192.168.65.1:53: i/o timeout)

Why is that?

答案1

得分: 2

对于那些将要查看这个问题的人,我找到了一个解决方案。
我的GOPATHGOBIN设置错误。我应该使用docker容器内部的go目录。
然后命令变成了:

docker run --rm -v $PWD:/t -w/t -e GOPATH=/t -e GOBIN=/t/bin golang:latest go get -v gopkg.in/olivere/elastic.v3

出于某些原因,这解决了DNS问题。我仍然不明白为什么,但如果我找到解释,我会在这里更新。

英文:

For those who will be looking at this question, I managed to find a solution.
My GOPATH and GOBIN have been wrongly set. I should have used the go directory inside the docker container.
The command then becomes:

docker run --rm -v $PWD:/t -w/t -e GOPATH=/t -e GOBIN=/t/bin golang:latest go get -v gopkg.in/olivere/elastic.v3

For some reasons, it solved the DNS issue. I still don't understand why, but if I stumble on an explanation, I'll update here.

huangapple
  • 本文由 发表于 2016年11月17日 17:48:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/40651554.html
匿名

发表评论

匿名网友

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

确定