Reputation: 20771
I've created the following docker-compose.yml:
version: "3"
services:
mongo:
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin
ports:
- '27017:27017'
I then start my containers:
docker-compose up
then I try to connect into MongoDb Compass(also tried through c# code), with the following:
But I always get a "Authentication failed" message:
I really don't understand what is going on. What am I missing.
Sorry for the dumb question...
Upvotes: 0
Views: 1556
Reputation: 130
I think it might be better to set ports to
ports:
- '27012:27017'
So you don't need to delete anything from your system.
Now you can connect as ussual, just change port to 27012
instead of 27017
Also this way you can run multiple monogdb's using more ports wthout any issues. In my case I still needed local mongodb running and because of that port 27017 was automatically connecting to it.
Upvotes: 0
Reputation: 312690
The behavior you're seeing suggests that there is already another mongodb instance running on your system (with different authentication credentials). Stop the Docker container and check to see if there is still a mongodb service listening on port 27017.
Upvotes: 1