I'm running an app with mongo db with docker.
Here is the mongodb part of the docker-compose file.
mongodb:
restart: always
image: mongo:3.6.3
container_name: "mongodb"
environment:
- MONGO_DATA_DIR=/data/db
- MONGO_LOG_DIR=/dev/nul
- MONGO_INITDB_ROOT_USERNAME=MasterUser
- MONGO_INITDB_ROOT_PASSWORD=MasterPassword
ports:
- 27017:27017
when i start the apps with docker-compose i see that mongodb is not detecting the root username and password therefore i can't login to mongodb and create user for my applications.
Strange thing is that, when i create a compose file only for mongodb it runs and uses the credentials i gave (MasterUser/MasterPassword)
i can also see that master user password and username are set in ENV in the container
docker exec -it mongodb env | grep -i master
MONGO_INITDB_ROOT_USERNAME=MasterUser MONGO_INITDB_ROOT_PASSWORD=MasterPassword
however they dont work to login to db
docker exec -it mongodb mongo -u MasterUser -p MasterPassword --authenticationDatabase admin MongoDB shell version v3.6.3 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.6.3 2020-07-18T19:27:22.378+0000 E QUERY [thread1] Error: Authentication failed. :
@(auth):6:1 @(auth):1:2 exception: login failed