Reputation: 77
I use the following lines to define a mongodb docker container with docker-compose:
mongo:
image: mongo
container_name: mongodb
hostname: ${host}
environment:
- MONGO_INITDB_ROOT_USERNAME=${user}
- MONGO_INITDB_ROOT_PASSWORD=${password}
ports:
- "${port}:27017"
volumes:
- ./mongodb/data:/data/db
Like this, I get an error (Authentication failed.
) when I try to connect to mongodb via MongoDB Compass. After two hours of despair I found out that it works when I remove the volumes
part in the docker-compose file.
What's the problem with the volume and how can I fix it?
Upvotes: 2
Views: 680
Reputation: 11
I got the same problem. My app works well without the volumes part. I solved the issue using docker compose down --volumes
(See prompt) and running again the command docker compose up
.
Upvotes: 1
Reputation: 77
I just solved the problem by my self. I had to delete everything that was already in the volume directory on my host-machine (the content of the ./mongodb/data
folder). I previously used the mongodb container without authentication. I assume it has something to do with that.
Upvotes: 2