title: how to save a docker redis container
body: <p>I'm having trouble creating an image of a docker redis container with the data in the redis database. At the moment I'm doing this:</p>
  <pre><code>docker pull redis
  docker run --name my-redis -p 6379:6379 -d redis
  redis-cli
  127.0.0.1:6379&gt; set hello world
  OK
  127.0.0.1:6379&gt; save
  OK
  127.0.0.1:6379&gt; exit
  docker stop my-redis
  docker commit my-redis redis_with_data
  docker run --name my-redis2 -p 6379:6379 -d redis_with_data
  redis-cli
  127.0.0.1:6379&gt; keys *
  (empty list or set)
  </code></pre>
  <p>I'm obviously not understanding something pretty basic here. Doesn't docker commit create a new image from an existing container?</p>
  <hr />
  <p>okay, i've been doing some digging. The default redis image on hub.docker uses a data-volume which is then mounted at /data in a container. In order to share this volume between containers, you have to start a new container with the following argument:</p>
  <pre><code>docker run -d --volumes-from &lt;name-of-container-you-want-the-data-from&gt; \
    --name &lt;new-container-name&gt; -p 6379:6379 redis
  </code></pre>
  <p>Note that the order of the arguments is important, otherwise docker run will fail silently.</p>
  <pre><code>docker volume ls
  </code></pre>
  <p>will tell you which data volumes have already been created by docker on your computer. I haven't yet found a way to give these volumes a trivial name, rather than a long random string.</p>
  <p>I also haven't yet found a way to mount a data-volume, but rather just use the <code>--volumes-from</code> command.</p>
  <hr />
  <p>Okay. I now have it working, but it's cludgey.</p>
  <p>With</p>
  <pre><code>docker volume ls
  docker volume inspect &lt;id of docker volume&gt;
  </code></pre>
  <p>you can find the path of the docker volume on the local file-system.
  You can then mount this in a new container as follows:</p>
  <pre><code>docker run -d -v /var/lib/docker/volumes/&lt;some incredibly long string&gt;/_data:/data \
     --name my-redis2 -p 6379:6379 redis
  </code></pre>
  <p>This is obviously not the way you're meant to do this. I'll carry on digging.</p>
  <hr />
  <p>I put all that i've discovered upto now in a blog post: <a href="https://medium.com/@ehrt74/what-you-have-to-know-before-creating-a-container-of-a-redis-docker-image-674f1c93ede0" rel="noreferrer">my blog post on medium.com</a></p>
  <p>Maybe that will be useful for somebody</p>