Docker-compose cannot find package (golang)

I am writing a simple application in GO and I have this folder structure

enter image description here

Docker-compose.yml file content:

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

      

Every time I run docker build I get this error message:

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 |
/usr/local/go/src/_/go/src/test_server/vendor/github.com/gin-gonic/gin (from $ GOROOT) test_server |
/go/src/_/go/src/test_server/vendor/github.com/gin-gonic/gin (from $ GOPATH)

This refers to the controller package. I am using github.com/kardianos/govendor for my package vendors. Do you know what's going on?

+3


source to share


3 answers


After a few hours, I was finally able to fix it. I ended up using a version of doker golang that didn't have git in it. I have to use golang: 1.8

I modified my Dockerfile like this and now it works like a charm



FROM golang:1.8

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

WORKDIR /go/src/app
COPY . .

RUN go install -v

CMD ["app"]

      

+1


source


You need to tell where to look for packages:

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

      



Or have a Dockerfile with the proper packages installed (recommended)

0


source


I think this is because your updated code is running, install it instead of running your old code.

You needed to install additional golang packages in the vendor directory that you call from your application.

0


source







All Articles