2019-03-25 17:49
浏览 120


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
RUN go get
RUN go get
RUN go install ./accounting/server

ENTRYPOINT [ "/go/bin/server" ]


Project structure:

enter image description here

How to solve this problem?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • douqi2804 2019-03-30 16:05

    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:


    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
    RUN go get
    RUN go get
    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!

    解决 无用
    打赏 举报

相关推荐 更多相似问题