简体   繁体   English

docker-compose找不到包

[英]docker-compose cannot find package

I'm writing a simple app in GO and I have this folder structure 我正在GO中编写一个简单的应用程序,我有这个文件夹结构

在此输入图像描述

The docker-compose.yml file content is: docker-compose.yml文件内容是:

version: '2'
services:
  db:
    image: rethinkdb:latest
    ports:
      - "38080:8080"
      - "38015:28015"
      - "39015:29015"
  api:
    image: golang:1.8-alpine
    volumes:
      - .:/go/src/test_server/
    working_dir: /go/src/test_server
    command: go run server.go
    container_name: test_server
    ports:
      - "8085:8085"
    links:
      - db
    tty: true

Everytime I run docker-compose up I receive this error message: 每次我运行docker-compose时,都会收到以下错误消息:

test_server | test_server | controllers/users.go:4:3: cannot find package "_/go/src/test_server/vendor/github.com/gin-gonic/gin" in any of: test_server | controllers / users.go:4:3:在以下任何一个中找不到包“_ / go / src / test_server / vendor / github.com / gin-gonic / gin”:test_server |
/usr/local/go/src/_/go/src/test_server/vendor/github.com/gin-gonic/gin (from $GOROOT) test_server | /usr/local/go/src/_/go/src/test_server/vendor/github.com/gin-gonic/gin(来自$ GOROOT)test_server |
/go/src/_/go/src/test_server/vendor/github.com/gin-gonic/gin (from $GOPATH) /go/src/_/go/src/test_server/vendor/github.com/gin-gonic/gin(来自$ GOPATH)

It's referring to the controllers package. 它指的是控制器包。 I'm using github.com/kardianos/govendor to vendor my packages. 我正在使用github.com/kardianos/govendor来提供我的软件包。 Do you know what's going on? 你知道发生了什么吗?

After many hours I finally could fix it. 几个小时后,我终于可以解决它了。 Resulted that I was using a docker golang version that it doesn't have git included. 导致我使用的是docker golang版本,它没有包含git。 I should use golang:1.8 我应该使用golang:1.8

I modified my Dockerfile like this and now it works like a charm 我像这样修改了我的Dockerfile,现在它就像一个魅力

FROM golang:1.8

RUN go get github.com/gin-gonic/gin

WORKDIR /go/src/app
COPY . .

RUN go install -v

CMD ["app"]

You need to tell go where find the packages: 你需要告诉去哪里找到包裹:

api:
  ...
  environment:
    - GOPATH=/go/src/test_server

Or have a Dockerfile with the proper packages installed (recommended) 或者安装了安装了正确软件包的Dockerfile(推荐)

I think it's because your updated code is running go install, not go run which your old code was running. 我认为这是因为您更新的代码正在运行安装,而不是运行您的旧代码运行。

You needed to install the extra golang packages into the vendor directory that you are calling from your app. 您需要将额外的golang软件包安装到您从应用程序调用的供应商目录中。

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

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