【发布时间】:2021-02-27 19:49:59
【问题描述】:
我无法连接到容器化的 mongodb 实例,来自应用程序或客户端的身份验证失败 (Robo 3T)
这是我的 docker compose 文件:
version: '3.4'
services:
db:
container_name : mongo
image: mongo
volumes:
- c:/data/db:/data/db
- c:/data/configdb:/data/configdb
ports:
- '27017:27017'
restart: always
environment:
AUTH: "yes"
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: dBPassword01
command: mongod
networks:
clusternetwork:
ipv4_address: 172.16.0.2
calculatorservice:
image: ${DOCKER_REGISTRY-}calculatorservice
build:
context: .
dockerfile: CalculatorService/Dockerfile
depends_on:
- db
networks:
clusternetwork:
ipv4_address: 172.16.0.3
networks:
clusternetwork:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.16.0.0/24
在我的应用程序设置中,我有:
"MongoDbSettings": {
"ConnectionString": "mongodb://dbroot:dBPassword01@172.16.0.2:27017",
"DatabaseName": "calculator-service"
}
但它失败并出现以下错误:
MongoDB.Driver.MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1.
---> MongoDB.Driver.MongoCommandException: Command saslStart failed: Authentication failed..
at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1.ProcessReply(ConnectionId connectionId, ReplyMessage`1 reply)
at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1.ExecuteAsync(IConnection connection, CancellationToken cancellationToken)
at MongoDB.Driver.Core.Authentication.SaslAuthenticator.AuthenticateAsync(IConnection connection, ConnectionDescription description, CancellationToken cancellationToken)
使用客户端 (Robo 3T) 我遇到了同样的身份验证问题:
我在这里错过了什么?
【问题讨论】:
-
在您的配置中: MONGO_INITDB_ROOT_USERNAME: root,那么为什么要尝试连接 dbroot?
标签: mongodb docker docker-compose