title: How to set docker mongo data volume
body: <p>I want to use Dockerizing MongoDB and store data in local volume.</p>
  
  <p>But .. failed ...</p>
  
  <p>It has <code>mongo:latest</code> images</p>
  
  <pre><code>kerydeMacBook-Pro:~ hu$ docker images
  REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
  mongo               latest              b11eedbc330f        2 weeks ago         317.4 MB
  ubuntu              latest              6cc0fc2a5ee3        3 weeks ago         187.9 MB
  </code></pre>
  
  <p>I want to store the mono data in <code>~/data</code>. so ---</p>
  
  <pre><code>kerydeMacBook-Pro:~ hu$ docker run -p 27017:27017 -v ~/data:/data/db --name mongo -d mongo
  f570073fa3104a54a54f39dbbd900a7c9f74938e2e0f3f731ec8a3140a418c43
  </code></pre>
  
  <p>But ... it not work...</p>
  
  <blockquote>
    <p>docker ps -- no daemon mongo</p>
  </blockquote>
  
  <pre><code>kerydeMacBook-Pro:~ hu$ docker ps
  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
  </code></pre>
  
  <p>try to run "mongo" --failed</p>
  
  <pre><code>kerydeMacBook-Pro:~ hu$ docker exec -it f57 bash
  Error response from daemon: Container f57 is not running
  </code></pre>
  
  <blockquote>
    <p>docker inspect mongo</p>
  </blockquote>
  
  <pre><code>kerydeMacBook-Pro:~ hu$ docker inspect mongo
  [
  {
      "Id": "f570073fa3104a54a54f39dbbd900a7c9f74938e2e0f3f731ec8a3140a418c43",
      "Created": "2016-02-15T02:19:01.617824401Z",
      "Path": "/entrypoint.sh",
      "Args": [
          "mongod"
      ],
      "State": {
          "Status": "exited",
          "Running": false,
          "Paused": false,
          "Restarting": false,
          "OOMKilled": false,
          "Dead": false,
          "Pid": 0,
          "ExitCode": 100,
          "Error": "",
          "StartedAt": "2016-02-15T02:19:01.74102535Z",
          "FinishedAt": "2016-02-15T02:19:01.806376434Z"
      },
  
  
  
  
  "Mounts": [
          {
              "Source": "/Users/hushuming/data",
              "Destination": "/data/db",
              "Mode": "",
              "RW": true
          },
          {
              "Name": "365e687c4e42a510878179962bea3c7699b020c575812c6af5a1718eeaf7b57a",
              "Source": "/mnt/sda1/var/lib/docker/volumes/365e687c4e42a510878179962bea3c7699b020c575812c6af5a1718eeaf7b57a/_data",
              "Destination": "/data/configdb",
              "Driver": "local",
              "Mode": "",
              "RW": true
          }
      ],
  </code></pre>
  
  <p><strong>If I do not set data volume, mongo image can work!</strong> </p>
  
  <p>But, when setting data volume, it can't. Who can help me?</p>