Reputation: 29
I downloaded a MongoDB docker image and wanted to mount a volume to persist data which was added into MongoDB. I am confused about whether the volume is mounted correctly and whether the container is using a volume or a bind mount.
First I created a volume:
docker volume create mongo-vol-1
Then I ran the docker run command:
docker run \
-p 30001:27017 \
--name mongo-1 \
--mount source=mongo-vol-1,target=/users/owner/documents/mongodb/data/\
mongo mongod
The container could start and test data could be added successfully. However, after exiting the container, the /users/owner/documents/mongodb/data directory was still empty.
I restarted the container and the test data could still be retrieved.
Is the data stored in the container instead of the host directory? If so, how to link the host directory to where MongoDB stores the data?
Also, I ran a docker inspect command:
docker inspect mongo-1
The results were:
...
"Mounts": [
{
"Type": "volume",
"Source": "mongo-vol-1",
"Target": "/users/owner/documents/mongodb/data"
}
...
"Volumes": {
"/data/configdb": {},
"/data/db": {}
},
...
From the result above, I am not sure if the target directory is a mount or a volume?
Upvotes: 0
Views: 2804
Reputation: 1006
Please do a docker inspect mongo-vol-1
and you will know where is the mounting point.
/users/owner/documents/mongodb/data
is the place inside the container which is from the container's understanding where to retrieve the data.
More details: https://docs.docker.com/engine/admin/volumes/volumes/#start-a-container-with-a-volume
Upvotes: 2