This is my docker-compose.yaml:
version: "2.0"
services:
mongo_container:
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
MONGO_INITDB_DATABASE: testdb
ports:
- "27017:27017"
volumes:
- ./mongodata:/data/db
And this in my spring configuration:
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.username=root
spring.data.mongodb.password=example
spring.data.mongodb.database=testdb
But everytime when I try to connect my app to Mongo I get following error in Docker console:
mongo_container_1 | 2020-03-31T07:37:24.803+0000 I ACCESS [conn2] SASL SCRAM-SHA-1 authentication failed for root on testdb from client 172.29.0.1:36628 ; UserNotFound: Could not find user "root" for db "testdb"
What am I doing wrong?
I tried to remove all containers with docker system prune and run it again but it still gives the same error.
spring.data.mongodb.database=admin