错误将Docker实例连接到mongoDB地图集

时间:2020-10-24 05:08:48

标签: mongodb docker go mongodb-atlas atlas

我制作了一个连接到MongoDB Atlas的go App,并且在本地运行时运行良好,但是当我尝试创建docker-compose时出现此错误

error parsing uri: lookup _mongodb._tcp.cluster0.mrknb.mongodb.net on 127.0.0.11:53: read udp 127.0.0.1:37379->127.0.0.11:53: i/o timeout

我的连接字符串是:

mongodb+srv://apiVentas:<password>@cluster0.mrknb.mongodb.net/<dbname>?retryWrites=true&w=majority

我的DockerFile是:

FROM golang:alpine AS builder

ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64

WORKDIR /build

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .

RUN go test ./...

RUN go build -o main .

WORKDIR /dist

RUN cp /build/main .

FROM scratch

COPY --from=builder /dist/main /

ENTRYPOINT ["/main"]

而Docker-compose是

version: "3"

services:
 web:
  container_name: apiVentas
  restart: always
  build: .
  ports:
      - "3000:3000"
  volumes:
    - .:/home/perajim/go/src/api.ventas
  dns:
   - 1.1.1.1
   - 1.0.0.1  
   - 8.8.8.8

我将IP添加到mongoDB Atlas列表中

是否需要在docker中进行一些配置?

1 个答案:

答案 0 :(得分:0)

MongoDB Atlas在端口27017上运行,更改端口绑定,然后尝试。