May 22, 2021 Docker From entry to practice
Data volumes can be used to back up, restore, and migrate the data in them.
Start with
--volumes-from
to create a container that loads the dbdata container volume and mount the /backup directory currently to the container from the local host.
The command is as follows:
$ sudo docker run --volumes-from dbdata -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata
After the container is
tar
volume is backed up as
/backup/backup.tar
If you want to recover data to a container, first create a container dbdata2 with a data volume.
$ sudo docker run -v /dbdata --name dbdata2 ubuntu /bin/bash
Then create another container, mount the dbdata2 container, and
untar
the backup file into the mounted container volume.
$ sudo docker run --volumes-from dbdata2 -v $(pwd):/backup busybox tar xvf
/backup/backup.tar