Hello guys, hope your having a good day. I also stumbled upon this issue yesterday and I found a solution for it, so basically if you check in docker the volumes you can see “data” which you defined for mongodb service and it’s status is “used”.
You can also see that another volume with a random hashed name also with status “used” is linked to mongodb service. If you click on it to check the content you can find the keyfile inside.
It turns out that every time you do docker-compose down and then re-run docker it doesn’t find the keyfile again because its not in the volume you created but a random one.
So this is what I did:
mongodb:
image: mongodb/mongodb-atlas-local
container_name: 'mongo'
restart: unless-stopped
ports:
- 27018:27017
volumes:
- mongodb_config:/data/configdb
- mongodb_data:/data/db
volumes:
mongodb_data:
mongodb_config:
I added a new volume to make sure it saved the config files and keyfile when generated the first time inside /data/configdb.
Hope this helps!