[英]Can't connect to MongoDB running from docker-compose
我無法連接到容器化 mongodb 實例,來自應用程序或客戶端的身份驗證失敗 (Robo 3T)
這是我的 docker 撰寫文件:
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
連接? 我會嘗試使用相同的用戶名, root
...
我的 Docker 也有類似的問題。 事實證明,我連接的是 localhost 實例,而不是 docker 實例,因為端口相同。 我收到Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1
因為用戶不匹配,但連接成功。 (現在聽起來很有趣)
我遇到了同樣的問題,但我的根用戶名配置得很好。 問題是我在 windows 上有robo 3t 和在wsl內運行的mongo容器。
解決方案是獲取我的wsl inet ip(ubuntu 中的ifconfig
或 windows 中的wsl hostname -I
),然后連接到這個 IP 而不是 localhost
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.