【问题标题】:Godep not working in docker containerGodep 不在 docker 容器中工作
【发布时间】:2016-04-09 04:42:26
【问题描述】:

我是 docker 新手,正在尝试为一个简单的 Go 应用程序制作一个 docker 容器。我正在使用 Godep 进行依赖管理。

这是我的 Dockerfile:

FROM pottava/golang:1.5

RUN go get github.com/tools/godep \
      && rm -rf /go/pkg /go/src

ADD ./ /go

ENV GOPATH /go
RUN godep go build -v -o ./bin/main ./src/main.go

当我尝试构建映像时,我收到以下错误:

...
 ---> 5cb6dd001eb3
Removing intermediate container 15eb0b298adb
Step 5 : ENV GOPATH /go
 ---> Running in 1c0043c3e963
 ---> 6cd0498af200
Removing intermediate container 1c0043c3e963
Step 6 : RUN godep go build -v -o ./bin/main ./src/main.go
 ---> Running in af2386d13c9a
godep: [WARNING]: godep should only be used inside a valid go package directory and
godep: [WARNING]: may not function correctly. You are probably outside of your $GOPATH.
godep: [WARNING]:   Current Directory: /go
godep: [WARNING]:   $GOPATH: /go
src/main.go:18:2: cannot find package "github.com/Sirupsen/logrus" in any of:
    /usr/local/go/src/github.com/Sirupsen/logrus (from $GOROOT)
    /go/Godeps/_workspace/src/github.com/Sirupsen/logrus (from $GOPATH)
    /go/src/github.com/Sirupsen/logrus
...

【问题讨论】:

    标签: docker godeps


    【解决方案1】:

    如果你设置了GOPATH,那意味着你定义了一个go workspace

    “在有效包中”执行 godep 意味着在以下位置执行它:

    $GOPATH/src/a/package
    

    确保在现有的 go 项目中执行 godep,克隆到 GOPATH/src

    简单测试:在您的计算机上尝试相同的命令(而不是在正在构建的 docker 映像中),当它工作时,在您的 Dockerfile 中重现设置和命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-19
      • 1970-01-01
      • 2023-01-18
      • 2019-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多