简体   繁体   中英

Go install can't find my internal packages in Dockerfile

So I'm trying to Dockerize my project which looks like this:

project/
  main.go
  package1/
  package2/
  package3/

And it also requires some outside packages such as github.com/gorilla/mux Note my project is internal on a github.company.com domain so I'm not sure if that matters. So here's my Dockerfile and yes, my GOPATH and GOROOT is set and PLEASE don't just tell me to read https://golang.org/doc/code.html . I have and am still am having this issue.

### STAGE 1: Build ###

FROM golang:1.10 as builder
WORKDIR /go/src/github.company.com/project-repo/project
COPY . .
RUN go get 
RUN go install <- ERROR HERE
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o executable -a -installsuffix cgo .

### STAGE 2: Setup ###

FROM python:3.6-alpine
COPY --from=builder /go/src/github.company.com/project-repo/project/executable /api/executable
CMD ["/api/executable"]

Then I run:

docker build -t myapp .

And get this error:

main.go: cannot find package github.company.com/project-repo/project/package1 in any of:
/usr/local/go/src/github.company.com/project-repo/project/package1 (from $GOROOT)
/go/src/github.company.com/project-repo/project/package1 (from $GOPATH)

And keep in mind those paths are correct. Why can't go install packages that are within itself?? Main.go imports package1, but for sure reason "go install" doesn't install packages inside itself..

Wow, golang really is picky about paths! It was just that I had assigned my working directory to the wrong place. There was another file in the tree:

WORKDIR /go/src/github.company.com/COMPANY/project-repo/project

在设置它的值之前,您是否制作了( mkdirWORKDIR

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM