如何从Docker容器中检索GOPATH? [英] How to retrieve GOPATH from Docker container?

查看:235
本文介绍了如何从Docker容器中检索GOPATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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



我已经尝试使用go工具和依赖关系将卷映射到容器。但是,这需要始终将GOPATH设置为当前工作空间,并且需要在主机上安装go工具和依赖项。 解决方案

您至少可以在启动您的容器时设置并传递这些环境变量

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

通过使用 -v 主机与您的容器共享一个文件夹。


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.

解决方案

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

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

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

这篇关于如何从Docker容器中检索GOPATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆