Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在docker中构建golang项目-在$GOPATH或$GOROOT中都找不到包_Docker_Go_Dockerfile_Grafana - Fatal编程技术网

在docker中构建golang项目-在$GOPATH或$GOROOT中都找不到包

在docker中构建golang项目-在$GOPATH或$GOROOT中都找不到包,docker,go,dockerfile,grafana,Docker,Go,Dockerfile,Grafana,我有一个路径为/Users/me/Documents/dev/grafana/src/github.com/grafana/grafana的项目。此项目使用其他几个项目,例如: /Users/me/Documents/dev/grafana/src/github.com/BurntSushi/toml /Users/me/Documents/dev/grafana/src/github.com/Unknwon/com 我可以在我的机器上构建所有东西,但是当我尝试在Docker中构建时,我得到了

我有一个路径为
/Users/me/Documents/dev/grafana/src/github.com/grafana/grafana
的项目。此项目使用其他几个项目,例如:

/Users/me/Documents/dev/grafana/src/github.com/BurntSushi/toml
/Users/me/Documents/dev/grafana/src/github.com/Unknwon/com
我可以在我的机器上构建所有东西,但是当我尝试在Docker中构建时,我得到了一堆
找不到包的错误

go install -v ./pkg/cmd/grafana-server
pkg/login/ldap_settings.go:7:2: cannot find package "github.com/BurntSushi/toml" in any of:
/usr/local/go/src/github.com/BurntSushi/toml (from $GOROOT)
/go/src/github.com/BurntSushi/toml (from $GOPATH)
pkg/services/notifications/codes.go:9:2: cannot find package "github.com/Unknwon/com" in any of:
/usr/local/go/src/github.com/Unknwon/com (from $GOROOT)
/go/src/github.com/Unknwon/com (from $GOPATH)
当我构建自己时,我有
$GOPATH=/Users/me/Documents/dev/grafana/
——在我的Dockerfile中我有:

FROM golang:latest AS build

RUN go version

ENV SRC_DIR=/go/src/github.com/grafana/grafana/
ENV GIT_SSL_NO_VERIFY=1

COPY . $SRC_DIR
WORKDIR $SRC_DIR

[... dependency installations ...]

# Building of Grafana
RUN npm run build
RUN go run build.go setup
RUN go run build.go build
我不明白为什么这个步骤(从
RUN-go-build.go-setup
步骤开始)一直报告它无法访问包


我四处寻找过类似的问题,但几乎所有相关的问题都没有指定building in Docker(而那些指定building in Docker的问题对这个场景没有太大帮助)。

你能试试下面的方法,看看是否有效

步骤1:安装go-dep(go-get-u github.com/golang/dep/cmd/dep)

步骤2:在项目中运行命令
dep init
。这将创建一个Gopkg.toml和Gopkg.lock

步骤3:更改docker文件

FROM golang:latest AS build

RUN go version

WORKDIR /go/src/github.com/grafana/grafana/
ENV GIT_SSL_NO_VERIFY=1

COPY . .
RUN go get -u github.com/golang/dep/cmd/dep && \
    dep ensure && \
    npm run build && \
    RUN go run build.go setup && \
    RUN go run build.go build && \

dep的工作原理是运行命令
dep确保
它会提取所有依赖项并将它们放在供应商目录中,您的代码可以轻松访问它们。

这就是我所使用的:,希望能给您提供一个参考。看起来它几乎希望这些路径已经存在。它们没有,并且应该在发出(我认为)时提取它们