How to retrieve GOPATH from Docker container?

2019-04-10 18:01发布

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条回答
再贱就再见
2楼-- · 2019-04-10 18:46

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.

查看更多
登录 后发表回答