gpt4 book ai didi

mongodb - go get mongo-go-driver 在 Dockerfile 中崩溃

转载 作者:数据小太阳 更新时间:2023-10-29 03:18:37 25 4
gpt4 key购买 nike

我的 Go 服务有点问题。我是 Go 的新手,我只想对一个连接到 mongodb 实例的小服务进行 docker 化。

我的代码在本地运行良好。所以这是我的 Dockerfile:

# build stage
FROM golang:alpine AS build-env
RUN apk add --no-cache git
ADD . .

RUN go get -v -u go.mongodb.org/mongo-driver
RUN go build -o mongotest

# final stage
FROM alpine
WORKDIR /app
COPY --from=build-env ./go/mongotest .

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
EXPOSE 8000
CMD ["./mongotest"]

当我构建它时,我收到此错误消息:

Step 6/18 : RUN go get -v -u go.mongodb.org/mongo-driver
---> Running in 4c45c601800d
Fetching https://go.mongodb.org/mongo-driver?go-get=1
Parsing meta tags from https://go.mongodb.org/mongo-driver?go-get=1 (status code 200)
get "go.mongodb.org/mongo-driver": found meta tag get.metaImport{Prefix:"go.mongodb.org/mongo-driver", VCS:"git", RepoRoot:"https://github.com/mongodb/mongo-go-driver.git"} at https://go.mongodb.org/mongo-driver?go-get=1
go.mongodb.org/mongo-driver (download)
package go.mongodb.org/mongo-driver: no Go files in /go/src/go.mongodb.org/mongo-driver
The command '/bin/sh -c go get -v -u go.mongodb.org/mongo-driver' returned a non-zero code: 1

/go/src 中没有 Go 文件 ... 好的,我能用它做什么?

奇怪的是,如果我替换

运行 go get -d -u go.mongodb.org/mongo-driver

运行 go get -d -u github.com/gorilla/mux

它有效!

mongo 驱动程序 repo 有问题吗?

最佳答案

MongoDB GitHub存储库建议使用此命令:

dep ensure -add "go.mongodb.org/mongo-driver/mongo@~1.0.0"

然后你可以看到golang包的url:go.mongodb.org/mongo-driver/mongo

尝试:

RUN go get -v -u go.mongodb.org/mongo-driver/mongo

关于mongodb - go get mongo-go-driver 在 Dockerfile 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57320861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com