我有一个具有结构的单声道回购。
mono-repo
- serviceA
- main.go
- Dockerfile
-serviceB
- main.go
- Dockerfile
go.mod
go.sum
serviceA中的Dockerfile包含以下代码。
FROM golang
ENV GO111MODULE=on
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
ENTRYPOINT ["/app/serviceA"]
我想构建Docker映像并在容器内包含来自我的mono-repo根的依赖项,我目前收到一条错误消息,说它在运行时找不到任何依赖项包
docker build -t serviceA
除非我将go.mod放置在serviceA内,否则看不到实现自己想要的东西的好方法。通过将go.mod放置在服务中,感觉就像我失去了在仓库中共享依赖项的服务优势一样。
答案 0 :(得分:1)
通过将go.mod放入服务内部,感觉就像我失去了在仓库中共享依赖项的服务优势一样。
但是,这是一种在here或there中看到的方法,其中COPY go.mod .
(和COPY go.sum .
)后跟RUN go mod download
。
#This is the ‘magic’ step that will download all the dependencies that are specified in
# the go.mod and go.sum file.
# Because of how the layer caching system works in Docker, the go mod download
# command will _ only_ be re-run when the go.mod or go.sum file change
# (or when we add another docker instruction this line)
RUN go mod download