3
votes

I'm writing a simple app in GO and I have this folder structure

enter image description here

The docker-compose.yml file content is:

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:

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)

It's referring to the controllers package. I'm using github.com/kardianos/govendor to vendor my packages. Do you know what's going on?

3

3 Answers

4
votes

After many hours I finally could fix it. Resulted that I was using a docker golang version that it doesn't have git included. I should 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"]
0
votes

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)

0
votes

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.