title: Am I mounting a volume for a MongoDB container correctly?
body: <p>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.</p>
  
  <p>First I created a volume:</p>
  
  <pre><code>docker volume create mongo-vol-1
  </code></pre>
  
  <p>Then I ran the docker run command:</p>
  
  <pre><code>docker run \
  -p 30001:27017 \
  --name mongo-1 \
  --mount source=mongo-vol-1,target=/users/owner/documents/mongodb/data/\  
  mongo mongod
  </code></pre>
  
  <p>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. </p>
  
  <p>I restarted the container and the test data could still be retrieved. </p>
  
  <p>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?</p>
  
  <p>Also, I ran a docker inspect command:</p>
  
  <pre><code>docker inspect mongo-1
  </code></pre>
  
  <p>The results were:</p>
  
  <pre><code>...
  "Mounts": [
  {
      "Type": "volume",
      "Source": "mongo-vol-1",
      "Target": "/users/owner/documents/mongodb/data"
  }
  ...
  "Volumes": {
       "/data/configdb": {},
       "/data/db": {}
          },
  ...
  </code></pre>
  
  <p>From the result above, I am not sure if the target directory is a mount or a volume?</p>