title: “Persistent Storage”
date: 2016-03-27T15:41:45
slug: persistent-storage
Attach a Host Directory to the Container
Create a volume container:
docker create -v /dbdata --name dbstore ubuntu /bin/true
Start a container with the volume container attached
docker run -d --volumes-from dbstore --name ubuntu ubuntu
Start a second container with the same volume container (shared)
docker run -d --volumes-from dbstore --name ubuntu2 ubuntu
You can use multiple --volumes-from parameters
Make a backup from the volume
docker run --rm --volumes-from ubuntu -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata
Restore the backup into a container
- Create a container with /dbdata as a storage point
docker run -v /dbdata --name dbstore2 ubuntu /bin/bash
- Mount the /dbdata Storage point to a new container, mount the local directory to /backup into the container (this includes backup.tar.gz) and extarct it in /dbdata
docker run --rm --volumes-from dbstore2 -v $(pwd):/backup ubuntu bash -c "cd /dbdata && tar xvf /backup/backup.tar --strip 1"
