英文:
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
对于那些将要查看这个问题的人,我找到了一个解决方案。
我的GOPATH
和GOBIN
设置错误。我应该使用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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论