这是我的docker文件,用于使用dep软件包管理器为Go构建docker映像。
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看起来像这样:
[[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镜像构建,但是随后我尝试运行它,出现以下错误:
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)
似乎缺少从供应商包中的导入。谁能给我提示如何解决它?
项目结构如下:
myproject
|-src
|-httpRouter
| |-httpRouter.go
|-requesthandler
|-requesthandler.go
|-main.go
|-vendor
|-Gopkg.toml
|-Gopkg.lock
httpRouter源代码:
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更改了相对路径:
立即获取这些错误。
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)