简体   繁体   中英

go get mongo-go-driver crashes in Dockerfile

I have a little problem with my Go service. I'm new to Go and I just want to dockerize a little service that just connect to a mongodb instance.

My code works fine locally. So here is my 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"]

When I build it, I have this error message :

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

no Go files in /go/src ... ok, what can I do with that?

The strange thing is that if I replace

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

by

RUN go get -d -u github.com/gorilla/mux

it works!

Is there a problem with mongo driver repo?

MongoDB GitHub repository recommend to use this command :

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

and you can see golang package url: go.mongodb.org/mongo-driver/mongo

Try:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM