-1

I have a simple Dockerfile that I am trying to build and run my Go REST API server.

My Dockerfile so far is:

FROM golang:latest
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]

When I run docker-compose up I get this error:

main.go:12:2: cannot find package "github.com/bradfitz/gomemcache/memcache" in any of:

I am using godeps and my vendor folder has all the libraries vendored, why isn't the build working in this case?

Do I have to tell it to look in the vendor folder?

Blankman
  • 259,732
  • 324
  • 769
  • 1,199
  • @MartinTournoij I just assume that the issue is that I have to give some sort of flag to look in the vendor/ folder for deps. – Blankman Sep 06 '18 at 00:38
  • 1
    No, you don't. The error output should actually says it's looking in the vendor directory (the part that you omitted). – Martin Tournoij Sep 06 '18 at 00:40

1 Answers1

1

The vendor directory does not function as expected if your source code lies outside of GOPATH (see https://github.com/golang/go/issues/14566). In the current golang:latest Docker image, GOPATH is set to /go so the simplest solution would be to copy your code into a subdirectory of /go/src and build from there.

svsd
  • 1,831
  • 9
  • 14