I try to create an image for my Golang application, but Docker just writes:
Step 7/9 : RUN go install ./accounting/server
---> Running in f998ba6a5efb
can't load package: package grpcProjects/multiService/accounting/server: cannot find package "grpcProjects/multiService/accounting/server" in any of:
/usr/local/go/src/grpcProjects/multiService/accounting/server (from $GOROOT)
/go/src/grpcProjects/multiService/accounting/server (from $GOPATH)
My Dockerfile:
FROM golang:1.10.4
ADD . /go/src/grpcProjects/multiService
WORKDIR /go/src/grpcProjects/multiService
RUN go get github.com/golang/protobuf/proto
RUN go get golang.org/x/net/context
RUN go get google.golang.org/grpc
RUN go install ./accounting/server
ENTRYPOINT [ "/go/bin/server" ]
EXPOSE 8080
Project structure:
How to solve this problem?
I've found a solution. Everything went wrong because I used this command from the root directory of the project:
$ docker build -t accounting_server ./accounting
And multiService/accounting
was my building directory, so file hierarchy in the image looked like that:
/go/src/grpcProjects/multiService
/go/src/grpcProjects/multiService/server
/go/src/grpcProjects/multiService/server/service
/go/src/grpcProjects/multiService/server/service/accounting.go
/go/src/grpcProjects/multiService/server/main.go
/go/src/grpcProjects/multiService/proto
/go/src/grpcProjects/multiService/proto/accounting.proto
/go/src/grpcProjects/multiService/proto/accounting.pb.go
/go/src/grpcProjects/multiService/Dockerfile
Docker just copied the contents of local /multiService/accounting
to /multiService
directory of the image. So I had to change Dockerfile a bit:
FROM golang:1.10.4
ADD . /go/src/grpcProjects/multiService
RUN go get github.com/golang/protobuf/proto
RUN go get golang.org/x/net/context
RUN go get google.golang.org/grpc
RUN go install grpcProjects/multiService/accounting/server
ENTRYPOINT [ "/go/bin/server" ]
EXPOSE 8080
And I built my container with the next command:
$ docker build -t accounting_server -f ./accounting/Dockerfile .
Still from the root directory so everything was copied to the image properly.
Thanks to everyone who replied!