Reputation: 1240
When I take docker containers down and up again, my MongoDB collections are all gone.
docker-compose up
and add a new database, collection, and document. docker-compose down
and then docker-compose up
. It works fine if I am just stopping and starting the containers though. My host machine is macOS Mojave 10.14 with Docker Desktop 2.1.
I have the following docker-compose.yaml version 3.4 file:
mongodb:
image: mongo:4.2.1
volumes:
- ./docker/data/mongodb:/var/lib/mongodb:rw
ports:
- target: 27017
published: 27018
protocol: tcp
I am not sure what I am doing wrong with the volume mounts. When I look on my host machine at ./docker/data/mongodb nothing is being written to it, ever. I went ahead and set permissions to 777 on that to see if it was a permissions issue, hail mary, I know.
Upvotes: 1
Views: 974
Reputation: 13113
You are missing quotes
volumes:
- "./docker/data/mongodb:/var/lib/mongodb"
Note: MongoDB by default points /data/db
Upvotes: 1
Reputation: 1814
From the docs here:
https://hub.docker.com/_/mongo
You will need to mount the custom volume into /data/db
, not /var/lib/mongodb
Upvotes: 0