我有一个 go 项目文件夹
my_project
|- common
|- library
|- golang
|- my_app
|- Dockerfile
|- go.mod
|- go.sum
|- main.go
Dockerfile 来自谷歌云官方示例:
FROM golang:1.15-buster as builder
WORKDIR /app
COPY go.* ./
RUN go mod download
COPY . ./
RUN go build -mod=readonly -v -o server
FROM debian:buster-slim
RUN set -x && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/server /server
CMD ["/server"]
go.mod 在同一个项目中使用了一个公共库,但属于一个私有存储库:
module run
go 1.15
require (
github.com/my/private/my_project/common/library/golang v0.0.0-00010101000000-000000000000
)
replace (
github.com/my/private/my_project/common/library/golang => ../common/library/golang
)
当我在路径下运行 docker buildmy_app来构建图像时,得到了这个错误:
...
=> ERROR [builder 4/6] RUN go mod download 1.0s
------
> [builder 4/6] RUN go mod download:
#13 0.934 go: github.com/my/private/my_project/golang@v0.0.0-00010101000000-000000000000: parsing /common/library/golang/go.mod: open /common/library/golang/go.mod: no such file or directory
------
executor failed running [/bin/sh -c go mod download]: exit code: 1
为什么它不能go.mod在当前路径中找到文件但使用/common/library/golang/go.mod?
慕哥9229398
相关分类