【发布时间】:2021-08-08 22:29:01
【问题描述】:
我的 Go 模块,存储在 GitHub 中,本地编译成功;但是,如果我尝试通过 docker 执行此操作,即使在本地位于同一文件夹中,对于子文件夹中的每个本地导入,我都会收到错误消息,抱怨我的本地包不存在:
=> ERROR [build 7/7] RUN go build -o myrepo-test . 0.6s
------
> [build 7/7] RUN go build -o myrepo-test .:
#14 0.535 main.go:10:2: no required module provides package github.com/myuser/myrepo-test/common; to add it:
#14 0.535 go get github.com/myuser/myrepo-test/common
#14 0.535 main.go:13:2: no required module provides package github.com/myuser/myrepo-test/scraper/data/process; to add it:
#14 0.535 go get github.com/myuser/myrepo-test/scraper/data/process
(....)
这是我的go.mod:
module github.com/myuser/myrepo-test
go 1.16
还有 docker 文件:
# use alpine due to its small footprint
FROM golang:1.16-buster AS build
WORKDIR /app
# download the required Go dependencies
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY *.go ./
# FAIL
RUN go build -o myrepo-test .
##########
# Deploy #
##########
FROM gcr.io/distroless/base-debian10
WORKDIR /
COPY --from=build /myrepo-test /myrepo-test
USER nonroot:nonroot
ENTRYPOINT ["/myrepo-test"]
CMD ["/myrepo-test"]
【问题讨论】: