Building golang project in docker - cannot find package in any of $GOPATH or $GOROOT

I have a project with the path /Users/me/Documents/dev/grafana/src/ This project uses several other projects, for example:


I can build everything fine on my machine, but when I try to build within Docker, I get a bunch of cannot find package errors.

go install -v ./pkg/cmd/grafana-server
pkg/login/ldap_settings.go:7:2: cannot find package "" in any of:
/usr/local/go/src/ (from $GOROOT)
/go/src/ (from $GOPATH)
pkg/services/notifications/codes.go:9:2: cannot find package "" in any of:
/usr/local/go/src/ (from $GOROOT)
/go/src/ (from $GOPATH)

When I build myself, I have $GOPATH=/Users/me/Documents/dev/grafana/ – in my Dockerfile I have:

FROM golang:latest AS build

RUN go version

ENV SRC_DIR=/go/src/


[... dependency installations ...]

# Building of Grafana
RUN npm run build
RUN go run build.go setup
RUN go run build.go build

I can’t figure out why this step (specifically, the RUN go run build.go setup step) keeps reporting that it can’t access the packages.

I’ve looked around for similar questions, but almost everything related doesn’t specify building in Docker (and the ones that do aren’t super helpful for this scenario).

You have not added you code /go/src/ inside the container.

Try running an explicit go get $SRC_DIR/...

I assume he did:


@NobbZ Yes I didn’t see it. I take it back. But I don’t see the directory being created.


You are executing the multi stage docker build incorrectly and as @NobbZ mentioned go get your dependencies.

FROM golang:1.7.3 as builder
WORKDIR /go/src/
RUN go get -d -v  
COPY app.go    .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .

FROM alpine:latest  
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /go/src/ .
CMD ["./app"] 

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.