drjyvoi734793 2018-08-19 08:14
浏览 77

Docker容器未找到所需的依赖项

So this my docker file for building docker image for Go which uses dep package manager.

FROM golang:1.8.5-jessie

# install dep
RUN go get github.com/golang/dep/cmd/dep

# create a working directory
WORKDIR /go/src/app

# add Gopkg.toml and Gopkg.lock
ADD Gopkg.toml Gopkg.toml
ADD Gopkg.lock Gopkg.lock

# install packages
RUN dep ensure --vendor-only

# add source code
ADD src src

# run main.go
CMD ["go", "run", "src/main.go"]

Gopkg.toml looks like this:

[[constraint]]
  name = "github.com/spf13/viper"
  version = "1.1.0"

[[constraint]]
  name = "github.com/gin-gonic/gin"
  version = "1.3.0"

[prune]
  go-tests = true
  unused-packages = true

Docker image builds, but then I try to run it I get these errors:

src/requestHandler/requestHandler.go:4:2: cannot find package "_/go/src/app/vendor/github.com/gin-gonic/gin" in any of:
        /usr/local/go/src/_/go/src/app/vendor/github.com/gin-gonic/gin (from $GOROOT)
        /go/src/_/go/src/app/vendor/github.com/gin-gonic/gin (from $GOPATH)
src/configReader/configReader.go:4:2: cannot find package "_/go/src/app/vendor/github.com/spf13/viper" in any of:
        /usr/local/go/src/_/go/src/app/vendor/github.com/spf13/viper (from $GOROOT)
        /go/src/_/go/src/app/vendor/github.com/spf13/viper (from $GOPATH)

It looks like import from vendor package is missing. Can anyone could give me a hint how to fix it?

Project structure as follows:

myproject
  |-src
    |-httpRouter
    |  |-httpRouter.go
    |-requesthandler
       |-requesthandler.go
    |-main.go
  |-vendor
  |-Gopkg.toml
  |-Gopkg.lock

httpRouter source code:

package httpRouter

import (
    "github.com/gin-gonic/gin"
    "../requestHandler"
)

func SetupRouter() *gin.Engine {
    router := gin.Default()
    v1 := router.Group("api/v1")
    {
        v1.POST("/submit", requestHandler.HandleSubmitEmailRequest)
    }
    return router
}

UPDATE changed relative paths:

Getting these errors now.

vendor/github.com/gin-gonic/gin/binding/protobuf.go:11:2: cannot find package "github.com/golang/protobuf/proto" in any of:
            /go/src/notification-gateway/vendor/github.com/golang/protobuf/proto (vendor tree)
            /usr/local/go/src/github.com/golang/protobuf/proto (from $GOROOT)
            /go/src/github.com/golang/protobuf/proto (from $GOPATH)
    vendor/github.com/gin-gonic/gin/logger.go:14:2: cannot find package "github.com/mattn/go-isatty" in any of:
            /go/src/notification-gateway/vendor/github.com/mattn/go-isatty (vendor tree)
            /usr/local/go/src/github.com/mattn/go-isatty (from $GOROOT)
            /go/src/github.com/mattn/go-isatty (from $GOPATH)
    vendor/github.com/gin-gonic/gin/binding/msgpack.go:12:2: cannot find package "github.com/ugorji/go/codec" in any of:
            /go/src/notification-gateway/vendor/github.com/ugorji/go/codec (vendor tree)
            /usr/local/go/src/github.com/ugorji/go/codec (from $GOROOT)
            /go/src/github.com/ugorji/go/codec (from $GOPATH)
    vendor/github.com/gin-gonic/gin/binding/default_validator.go:11:2: cannot find package "gopkg.in/go-playground/validator.v8" in any of:
            /go/src/notification-gateway/vendor/gopkg.in/go-playground/validator.v8 (vendor tree)
            /usr/local/go/src/gopkg.in/go-playground/validator.v8 (from $GOROOT)
            /go/src/gopkg.in/go-playground/validator.v8 (from $GOPATH)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler