2019-07-19 17:38
浏览 771

在Docker中找不到Go mod文件夹

I'm very new to go modules and am trying to take a project and update it to use them as they seem like a really great way to finally handle my dependencies. However, I'm having an issue getting things to build in Docker.

I have a project with a main.go and a go.mod file (which references both private/local repos as well as public ones like go.uber.org/zap). I've named my module github.internal.com/team_name/project_name I've vendored up my dependencies. So, my project structure looks like:

- main.go
- internal
  - utils.go
- go.mod (github.internal.com/team_name/project_name)
- vendor
  - go.uber.org
  - private.repo.com

Then, in main.go I import

import (

All of this works great and I can run go build no problem.

The issue comes when I try to build using Docker. In my Dockerfile I run

COPY . /go/src/github.internal.com/team_name/project_name
WORKDIR /go/src/github.internal.com/team_name/project_name
RUN CGO_ENABLED=0 GOOS=linux go build -a -o slaxtract main.go

When I run docker build it returns:

main.go:7:2: cannot find package "github.internal.com/team_name/project_name/internal" in any of:
    /go/src/github.internal.com/project_name/team_name/vendor/github.internal.com/project_name/team_name/internal (vendor tree) 
    /usr/local/go/src/github.internal.com/team_name/project_name/internal (from $GOROOT)
    /go/src/github.internal.com/team_name/project_name/internal (from $GOPATH)

How do I get to the right directory to recognize all of my files in my module?

Thanks in advance!

图片转代码服务由CSDN问答提供 功能建议

我刚开始使用模块,正在尝试进行项目并对其进行更新以使用它们, 就像是一种很好的方式来最终处理我的依赖关系。 但是,在将内容构建到Docker时遇到了问题。</ p>

我有一个项目,其中包含 main.go </ code>和 go.mod </ code>文件(该文件同时引用了私有/本地存储库以及公共代码(例如 go.uber.org/zap </ code>))。 我已经将模块命名为 github.internal.com/team_name/project_name </ code>我已经提供了依赖项。 因此,我的项目结构如下:</ p>

- main.go 
- go.mod(github.internal。  com / team_name / project_name)
 </ code> </ pre> 

然后,用 main.go </ code>我导入</ p>

“ github.internal.com/team_name/project_name/internal"
” go.uber.org/  zap“ 
 </ code> </ pre> 

所有这些都很好,我可以运行 go build </ code>没问题。</ p> \ n

当我尝试使用Docker进行构建时出现问题。 在我的Dockerfile中,运行</ p>

  ENV GOPATH / go 
COPY。  /go/src/github.internal.com/team_name/project_name
WORKDIR /go/src/github.internal.com/team_name/project_name
RUN CGO_ENABLED = 0 GOOS = linux go build -a -o slaxtract main.go 
  </ code> </ pre> 

当我运行 docker build </ code>时,它返回:</ p>

  main.go:7:  2:在以下任何位置都找不到软件包“ github.internal.com/team_name/project_name/internal”:
 /go/src/github.internal.com/project_name/team_name/vendor/github.internal.com/project_name/team_name  /内部(供应商树)
 /usr/local/go/src/github.internal.com/team_name/project_name/internal(来自$ GOROOT)
 /go/src/github.internal.com/team_name/project_name/ 内部的(来自$ GOPATH)
 </ code> </ pre> 

如何进入正确的目录以识别模块中的所有文件?</ p> < p>预先感谢!</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题