需要帮助以在GO Workspace(多模制)模式下创建Docker容器
我需要帮助,我正在GO工作区工作,并且使用共同功能在工作区中有多个项目。因此,我要做的是制作一个单独的模块,该模块包含其他模块使用的所有常见功能。
所有模块都可以在我们使用GO工作区时共享其代码。
文件结构如下:
Workspace
│
├── Project1
│ ├── main.go
│ ├── docker-compose.yml
│ ├── Dockerfile
│ └── go.mod
│
├── Project2
│ ├── main.go
│ ├── docker-compose.yml
│ ├── Dockerfile
│ └── go.mod
│
├── Common
│ ├── functionality.go
│ └── go.mod
│
└── go.work
project1和project2使用common/fuctional.go
中的功能,通过将它们导入项目中。
当我运行docker -compose -d
命令中的project1
中,它说您在项目中导入的公共模块不在goroot中。 因为在这里Docker仅在目录中的文件Project1
中容纳文件,
我该如何分别dockerize project1
和project2
???
I need help, I'm working in the go workspace and there are multiple projects in the workspaces using the common functionality. So, What I did is to make a separate module that contains all the common functionalities that are used by the other modules.
All modules can share their code as we are using the go workspace.
The file structure is as follows:
Workspace
│
├── Project1
│ ├── main.go
│ ├── docker-compose.yml
│ ├── Dockerfile
│ └── go.mod
│
├── Project2
│ ├── main.go
│ ├── docker-compose.yml
│ ├── Dockerfile
│ └── go.mod
│
├── Common
│ ├── functionality.go
│ └── go.mod
│
└── go.work
Project1 and Project2 use the functionalities that are in the common/functionality.go
by importing them into the project.
when I run the docker-compose up -d
command in project1
It says the common module that you import in the project is not in the GOROOT.
because here docker only containerizes the files that are in the directory Project1
How can I dockerize separately Project1
and Project2
???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要编译您的应用程序,编译器需要所有导入的软件包。当您构建Docker映像时确定可用的文件;在您的情况下,这将是
project1
(例如)。这意味着,当您在dockerfile
中运行时,
唯一可用的文件是project1
文件夹中的文件。编译器将检查一个工作空间文件,但找不到一个(因为它在上下文中)。您可以通过更改
上下文
来解决此问题,以包括完整的工作区,例如project1/docker-compose.yml
:(您需要更新
dockerfile
也是因为您将在子目录等中复制)。但是,以上并不是真正理想的(它在某种程度上打败了将项目放在单独的文件夹中的地步)。根据您的发布过程,更好的选项可能是检查所有内容(例如git repo),做
go get -u
(更新go.mod
) ,然后构建Docker映像(允许从存储库中检索依赖项)。To compile your application the compiler requires all imported packages. When you build a docker image the
context
determines what files are available; in your case this will beProject1
(for example). This means that when you rungo build
in yourDockerfile
the only files available are those in theProject1
folder. The compiler will check for a workspace file but will not find one (because it's not in the context).You can work around this by changing the
context
such that it includes the full workspace e.g.Project1/docker-compose.yml
:(you will need to update your
Dockerfile
as well because you will be copying in subdirectories etc).However the above is not really ideal (it somewhat defeats the point of putting the projects in separate folders). Depending upon your release process a better option might be to check everything in (e.g. to a Git repo), do a
go get -u
(to update thego.mod
), and then build the docker image (allowing go to retrieve the dependencies from the repo).