这是我的。
MONGO_HOST_TEST=0.0.0.0
MONGO_PORT_TEST=27018
MONGO_USER_TEST=admin
MONGO_PASS_TEST=admin123
MONGO_DB_TEST=admin
And docker-compose.yml
version: "3"
services:
mongo-test:
image: mongo:latest
container_name: mongo-db-test
restart: always
environment:
MONGO_INITDB_DATABASE: test_db
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin123
MONGODB_APPLICATION_DATABASE: ${MONGO_DB}
MONGODB_APPLICATION_USER: ${MONGO_USER}
MONGODB_APPLICATION_PASS: ${MONGO_PASS}
ports:
- "27018:27018"
My problem is I can t connect to the server. I don t understand why when I configure it like that but when I use it sudo docker exec -it mongo-db-test bash
and next step mongosh --host 127.0.0.1 --port 27018 -u admin -p admin123 --authenticationDatabase admin
. And it returns the error of unable to authenticate
Error :
Current Mongosh Log ID: 65850e95f1898ea03b04eb0a Connecting to: mongodb://<credentials>@127.0.0.1:27018/?directConnection=true&serverSelectionTimeoutMS=2000&authSource=admin&appName=mongosh+2.1.1 MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27018