Official documentation on restoring Docker volumes goes here but it does need some further explanation. Let's break it down.

To restore Docker volume you have to create target volume first:

docker volume create VOLUME_NAME

VOLUME_NAME - volume name should be the same as backed up one.

To actually restore the volume from backup:

docker run --rm --volumes-from DESTINATION_CONTAINER \
-v $(pwd):/backup DESIRED_IMAGE \
bash -c "cd /MOUNT_POINT_IN_THE_CONTAINER \
&& tar xvf /backup/ARCHIVE_NAME_.tar --strip 1"

DESTINATION_CONTAINER - is our new container
DESIRED_IMAGE - an image to be used as temporary environment, this may be ubuntu, busybox or whatever
MOUNT_POINT_IN_THE_CONTAINER - mount point inside our container, where data stored
ARCHIVE_NAME - our backup name

Take a look particularly at "--strip 1" argument in "tar" command. This means you unpack 1 level folder from archive, but often you need to this to 2, as restored volume may not work due to path errors. Also you may want to remove "v" flag from "xvf" tar command argument to make terminal output more clear.

No comments yet