简体   繁体   English

如何从Docker容器配置go sdk和GOPATH?

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

I'm trying to configure golang project with Jetbrains Gogland and docker compose. 我正在尝试使用Jetbrains Gogland和docker compose配置golang项目。 I want to use GOPATH and go from the docker container. 我想使用GOPATH并从docker容器中转到。 I mean using the go installation from the container for the autocomplete etc without installing golang on the local machine. 我的意思是从容器中使用go安装进行自动完成等操作,而无需在本地计算机上安装golang。 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. 之后,我想将我的back文件夹部署到Docker容器中的/go/src/app中。 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. 问题是,当我开发项目时,我不能使用自动完成功能,因为该项目不在我的本地GOPATH中,并且docker容器和本地计算机上有不同的golang版本,我已经阅读了问题,但我仍然可以解决我的问题。

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. 在docker中挂载卷意味着您从容器“隐藏”该文件夹的内容,而使用主机上的文件。 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. 这意味着您不能在容器中安装Go,然后再安装文件夹并将该位置用作Go源。 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. 如果您在考虑:我只是将事情挂载到另一个位置,请执行一些symlink magic /复制文件操作,这是一个糟糕的主意,无济于事。

Gogland supports remote debugging as of EAP 10, released aa few weeks ago. Gogland自几周前发布的EAP 10开始支持远程调试。 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. 这样,您可以在计算机上安装Go和源代码,但可以在容器中运行它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM