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?
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.