使用内部软件包为golang API构建docker映像时出现问题,因为内部软件包无法导入

时间:2020-06-08 15:43:03

标签: docker go docker-compose directory-structure go-packages

当我在本地生成程序时,它的构建就完美了。但是,当我将以下内容复制到docker并尝试构建映像时,我遇到了该问题的说法,即无法导入软件包。在docker中支持go软件包处理似乎是一个罕见的问题。

文件夹结构

-go
  |
  -bin
  -pkg
  -src
    |
    -github(github packages)
    -Models (Models package)
    -main.go

我正在运行的程序:

FROM golang:latest
ENV GOPATH /go
RUN mkdir /app
ADD . /app
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]

该问题正在出现:

PS C:\Users\Rj-Dev\go\SRC> docker build -t my-go-app .
Sending build context to Docker daemon  81.34MB
Step 1/7 : FROM golang:latest
 ---> 05feda542433
Step 2/7 : ENV GOPATH /go
 ---> Using cache
 ---> 210da42c97c8
Step 3/7 : RUN mkdir /app
 ---> Using cache
 ---> 84e671cd147b
Step 4/7 : ADD . /app
 ---> 5c158421b580
Step 5/7 : WORKDIR /app
 ---> Running in 85171b79610a
Removing intermediate container 85171b79610a
 ---> 63562e5f52a4
Step 6/7 : RUN go build -o main .
 ---> Running in 6cf4814ebed3
BookingsByProjectsController.go:4:2: cannot find package "Models" in any of:
        /usr/local/go/src/Models (from $GOROOT)
        /go/src/Models (from $GOPATH)
main.go:8:2: cannot find package "github.com/denisenkom/go-mssqldb" in any of:
        /usr/local/go/src/github.com/denisenkom/go-mssqldb (from $GOROOT)
        /go/src/github.com/denisenkom/go-mssqldb (from $GOPATH)
API_Configurations.go:9:2: cannot find package "github.com/gorilla/mux" in any of:
        /usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
        /go/src/github.com/gorilla/mux (from $GOPATH)
main.go:9:2: cannot find package "github.com/jinzhu/gorm/dialects/mssql" in any of:
        /usr/local/go/src/github.com/jinzhu/gorm/dialects/mssql (from $GOROOT)
        /go/src/github.com/jinzhu/gorm/dialects/mssql (from $GOPATH)
API_Configurations.go:10:2: cannot find package "gopkg.in/natefinch/lumberjack.v2" in any of:
        /usr/local/go/src/gopkg.in/natefinch/lumberjack.v2 (from $GOROOT)
        /go/src/gopkg.in/natefinch/lumberjack.v2 (from $GOPATH)
The command '/bin/sh -c go build -o main .' returned a non-zero code: 1

出于某种原因,泊坞窗无法找到要安装的内部和外部软件包。 但是我可以在本地构建它。为什么我不能在docker中构建它?

0 个答案:

没有答案