I'm trying to create a mongodb service that runs in a docker container. My purpose is persist all the data inside container in the host machine. For this I have a docker-compose.yml file, whose content is:
version: '3.2'
services:
mongodb:
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: myrootmongousername
MONGO_INITDB_ROOT_PASSWORD: myrootmongopassword
MONGO_INITDB_DATABASE: dbnameiwanttocreate
ports:
- '27010:27017'
volumes:
- 'mongodata:/data'
As you can see, my volumes section declares to drop all content of /data folder inside container into mongodata folder in host. I created a folder named mongodata just at the same height that my docker-compose.yml file.
myprojectfolder
|__docker-compose.yml
|__mongodata
When I do docker-compose up it creates a container and I can connect and so on. However, my mongodata folder is completely empty. That's cannot be true, because if I go inside docker container (docker exec -it <container-id> bash) and explore /data folder, it is not empty at all.
What is my mistake here?
Thanks!