英文:
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 "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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论