如何从Docker容器中获取GOPATH?

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

How to retrieve GOPATH from Docker container?

问题

我的目标是每个项目都有一个独立的Go工作区。

是否可以从正在运行的Docker容器中检索Go工作区和Go环境变量,以供IDE或文本编辑器用于开发?

我已经尝试过将卷映射到容器中,其中包含Go工具和依赖项。但这需要始终将GOPATH设置为当前工作区,并且需要在主机上安装Go工具和依赖项。

英文:

My objective is to have a self contained Go Workspace per project.

Is it possible to retrieve a Go workspace and Go environment variables from a running Docker container to be used by an IDE or Text Editor for development?

I have already tried mapping a volume to the container with the go tools and dependencies. But that requires always setting the GOPATH to the current workspace, and requires to have the go tools and dependencies on the host.

答案1

得分: 0

你可以在启动容器时至少设置和传递这些环境变量:

docker run -e "GOPATH=/a/mounted/path" -v [host-src:]container-dest --rm -it <yourImage>

通过使用-v,你可以允许主机与容器共享一个文件夹。

英文:

You can at least set and pass those environment variable when launching your container:

docker run -e &quot;GOPATH=/a/mounted/path&quot; -v [host-src:]container-dest --rm -it &lt;yourImage&gt;

By using -v, you allow your host to share a folder with your container.

huangapple
  • 本文由 发表于 2016年2月29日 04:35:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/35687929.html
匿名

发表评论

匿名网友

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

确定