【问题标题】:MongoDB Connection Error (SASL) with Docker - Windows 10Docker 的 MongoDB 连接错误 (SASL) - Windows 10
【发布时间】:2021-07-26 07:44:03
【问题描述】:

我正在开发一个包含 2 个文件夹的移动应用项目:

  • 前端(8080 作为本地端口)
  • 后端,用 Go 编写

每个文件夹都适合 Docker 中的容器。

为了便于管理,我将这两个部分收集在同一个文件夹中。

后端分为5个容器:

  • 蒙哥
  • redis
  • redis_commander (8082)
  • mongo_express (8081)
  • 后端 (5000)

最后一个后端容器 (5000) 导致以下 SASL 错误:

/app/db/db.go:53 +0xbf

2021/07/22 10:15:15 Database:mongo:27017

panic: server returned error on SASL authentication step: BSON field 'saslContinue.mechanism' is an unknown field.

同时,我也:

  • 删除了容器、卷和图像
  • 每个部分都重新构建了几次
  • 与创建系统的同事一起审查我的配置文件

现在,我想知道我是否拼错或遗漏了配置文件中的参数:

docker-compose.yml

version: '3.6'
services:
  backend:
    build:
      context: ./src
    restart: on-failure
    ports:
      - "5000:8080" 
    expose:
      - 5000
    networks:
      - backend-network
    depends_on:
      - mongo
      - redis
    env_file:
      - backend_config.env

  mongo:
    image: mongo
    restart: on-failure
    volumes:
      - db-volume:/data/db
      - dbconfig-volume:/data/configdb
    networks:
      - backend-network
    env_file:
      - db_config.env

  mongo-express:
    image: mongo-express
    restart: on-failure
    ports:
      - 8081:8081
    networks:
      - backend-network
    depends_on:
      - mongo
    env_file:
      - db_config.env

  redis:
    image: redis:6.0.3-buster
    restart: on-failure
    networks:
      - backend-network

  redis-commander:
    image: rediscommander/redis-commander:latest
    restart: on-failure
    ports:
    - 8082:8082
    networks:
      - backend-network
    depends_on:
      - redis
    environment:
      - REDIS_HOST=redis
      - PORT=8082


volumes:
  db-volume:
  dbconfig-volume:

networks:
  backend-network:

backend_config.env

MONGODB_USERNAME=root
MONGODB_PASSWORD=example

DATABASE=mongo:27017
DATABASE_NAME=admin

ACCESS_SECRET=abc
REFRESH_SECRET=xyz

db_config.env

MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=example

ME_CONFIG_MONGODB_ADMINUSERNAME=root
ME_CONFIG_MONGODB_ADMINPASSWORD=example

ME_CONFIG_MONGODB_SERVER=mongo
ME_CONFIG_MONGODB_PORT=27017

我在 mongo-express 容器中也有这些消息:

(node:8) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!

(node:8) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

Could not connect to database using connectionString: mongodb://root:example@mongo:27017/"

(node:8) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mongo:27017] on first connect [Error: getaddrinfo EAI_AGAIN mongo

at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {

name: 'MongoNetworkError'

}]

at Pool.<anonymous> (/node_modules/mongodb/lib/core/topologies/server.js:441:11)

at Pool.emit (events.js:314:20)

at /node_modules/mongodb/lib/core/connection/pool.js:564:14

at /node_modules/mongodb/lib/core/connection/pool.js:999:11

at /node_modules/mongodb/lib/core/connection/connect.js:32:7

at callback (/node_modules/mongodb/lib/core/connection/connect.js:283:5)

at Socket.<anonymous> (/node_modules/mongodb/lib/core/connection/connect.js:313:7)

at Object.onceWrapper (events.js:421:26)

at Socket.emit (events.js:314:20)

at emitErrorNT (internal/streams/destroy.js:92:8)

at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)

at processTicksAndRejections (internal/process/task_queues.js:84:21)

(node:8) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

(node:8) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

(node:8) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

Could not connect to database using connectionString: mongodb://root:example@mongo:27017/"

(node:8) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mongo:27017] on first connect [Error: connect ECONNREFUSED 172.18.0.5:27017

at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {

name: 'MongoNetworkError'

}]

at Pool.<anonymous> (/node_modules/mongodb/lib/core/topologies/server.js:441:11)

at Pool.emit (events.js:314:20)

at /node_modules/mongodb/lib/core/connection/pool.js:564:14

at /node_modules/mongodb/lib/core/connection/pool.js:999:11

at /node_modules/mongodb/lib/core/connection/connect.js:32:7

at callback (/node_modules/mongodb/lib/core/connection/connect.js:283:5)

at Socket.<anonymous> (/node_modules/mongodb/lib/core/connection/connect.js:313:7)

at Object.onceWrapper (events.js:421:26)

at Socket.emit (events.js:314:20)

at emitErrorNT (internal/streams/destroy.js:92:8)

at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)

at processTicksAndRejections (internal/process/task_queues.js:84:21)

(node:8) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

(node:8) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

(node:8) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

非常感谢您。

【问题讨论】:

    标签: mongodb docker


    【解决方案1】:

    我收到此错误,在我的情况下,这是 mongoimport 的版本不匹配。我正在安装的系统安装了 Ubuntu (21) 分发 apt 版本,该版本安装了 mongoimport --version 的“built-without-version-string”(wtf?我的话)。我安装了最新版本 100.5.0 并且错误消失了。

    因此,即使您不使用 mongoimport,如果版本不匹配,其他 mongo 实用程序也可能会出现此错误。

    【讨论】:

      猜你喜欢
      • 2019-10-17
      • 1970-01-01
      • 2019-01-27
      • 1970-01-01
      • 2019-07-27
      • 2021-07-24
      • 1970-01-01
      • 2017-09-14
      • 1970-01-01
      相关资源
      最近更新 更多