dsgoj7457
2017-12-03 13:15
浏览 98

docker内的golang错误

I get a strange error in docker when building my go app:

./main.go:31:9: cannot use db (type *"github.com/khwerhahn/somerepo/vendor/github.com/jinzhu/gorm".DB) as type *"app/vendor/github.com/jinzhu/gorm".DB in argument to Migrate  
The command '/bin/sh -c go-wrapper install' returned a non-zero code: 2

Could somebody hint me into the right direction, because locally the app runs just fine. Its just inside the docker container. I use glide to manage dependencies.

Dockerfile:

FROM golang:1.9
WORKDIR /go/src/app
COPY . .
RUN go-wrapper download
RUN go-wrapper install

CMD ["go-wrapper", "run"]

//// Edit This is how my structure looks. Glide manages the vendor folder. The docker build does the rest.

enter image description here

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

构建go应用时,我在docker中遇到一个奇怪的错误:

   ./ main.go:31:9:不能将数据库(类型*“ github.com/khwerhahn/somerepo/vendor/github.com/jinzhu/gorm” .DB)用作类型*“ app / vendor / github  .com / jinzhu / gorm”。迁移参数
中的数据库
命令'/ bin / sh -c go-wrapper install'返回了非零代码:2 
   
 
  

有人可以向我提示正确的方向,因为该应用在本地运行正常。 它只是在docker容器中。 我使用 glide 来管理依赖项。

Dockerfile:

  FROM golang:1.9 
WORKDIR / go / src / app 
COPY。  。
RUN go-wrapper下载
RUN go-wrapper安装
 
CMD [“ go-wrapper”,“ run”] 
   
 
 

////编辑 这是我的结构外观。 Glide 管理供应商文件夹。 剩下的工作由docker build完成。

”在此处输入图片描述“

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzhonggua4229 2017-12-04 16:56
    已采纳

    It's because go get is called by go-wrapper download. This fetches the dependencies from the remote instead of looking in the vendor folder.

    If your libraries are already vendored and the code is in the vendor folder, all you should have to do is go run or go install.

    and why do you need go-wrapper when you can just do.

    RUN glide install
    RUN go install
    WORKDIR "../bin"
    RUN myapp
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题