How can I configure go sdk and GOPATH from docker container?

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

How can I configure go sdk and GOPATH from docker container?

问题

我正在尝试使用Jetbrains Gogland和Docker Compose配置Golang项目。我想在Docker容器中使用GOPATH和go。也就是说,我想在容器中使用go安装来进行自动补全等操作,而不在本地机器上安装golang。
项目结构如下:

项目根目录
    docker-compose.yml
    back|
         Dockerfile
         main.go
         其他一些包
    front|
         所有前端文件...

之后,我想将我的back文件夹部署到Docker容器中的/go/src/app目录中。问题是,当我开发项目时,由于该项目不在我的本地GOPATH中,并且Docker容器和我的本地机器上有不同的golang版本,所以我无法使用自动补全。
我已经阅读了这个问题,但仍然无法解决我的问题。

英文:

I'm trying to configure golang project with Jetbrains Gogland and docker compose. I want to use GOPATH and go from the docker container. I mean using the go installation from the container for the autocomplete etc without installing golang on the local machine.
the project structure is:

project root
    docker-compose.yml
    back|
         Dockerfile
         main.go
         some other packages
    front|
         all the front files...

After that, I want to deploy my back folder to the /go/src/app in the docker container. The problem is that when I develop the project I can''t use autocomplete as this project is not in my local GOPATH and there are different golang versions in the docker container and on my local machine
I already read this question but I still can't solve my issue.

答案1

得分: 1

目前这是不可能的。我也看不到未来如何可能。在Docker中挂载卷意味着你将该文件夹的内容从容器中“隐藏”,而是使用主机上的文件。因此,每当你从机器上挂载目录时,该实例的容器文件将无法在机器上使用。这意味着你不能在容器中安装Go,然后挂载一个文件夹并将该位置用于Go源代码。如果你在想:我只需将东西挂载到另一个地方,进行一些符号链接魔法/复制文件,那只是一个导致无法实现的坏主意。

Gogland从EAP 10开始支持远程调试,这是几周前发布的。这使得你可以调试在容器中或远程主机上运行的应用程序。因此,你可以在机器上安装Go和源代码,但将它们运行在容器中。

英文:

At the moment this is not possible. Nor do I see how it could be possible in the future. Mounting a volume in docker means you "hide" the contents of that folder from the container and use the files on the host instead. As such, any time you'll mount the directory from your machine, your container files from that instance won't be available to the machine. This means you can't have Go installed in the container and then mount a folder and use that location for the Go sources. If you are thinking: I'll just mount things in another place, do some symlink magic / copy files around, that's just a bad idea that leads to nowhere.

Gogland supports remote debugging as of EAP 10, released a a few weeks ago. This allows you to debug applications running in containers or on remote hosts. As such, you can install Go, and the source code on your machine but have them running in containers.

huangapple
  • 本文由 发表于 2017年7月23日 23:56:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/45267060.html
匿名

发表评论

匿名网友

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

确定