How to port data-only volumes from one host to another?

前端 未结 5 1692
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 15:34

As described in the Docker documentation on Working with Volumes there is the concept of so-called data-only containers, which provide a volume that can be mounted

5条回答
  •  暖寄归人
    2020-11-29 15:55

    The official answer is available in the section "Backup, restore, or migrate data volumes":

    BACKUP:

    sudo docker run --rm --volumes-from DATA -v $(pwd):/backup busybox tar cvf /backup/backup.tar /data
    
    • --rm: remove the container when it exits
    • --volumes-from DATA: attach to the volumes shared by the DATA container
    • -v $(pwd):/backup: bind mount the current directory into the container; to write the tar file to
    • busybox: a small simpler image - good for quick maintenance
    • tar cvf /backup/backup.tar /data: creates an uncompressed tar file of all the files in the /data directory

    RESTORE:

    # create a new data container
    $ sudo docker create -v /data --name DATA2 busybox true
    # untar the backup files into the new container᾿s data volume
    $ sudo docker run --rm --volumes-from DATA2 -v $(pwd):/backup busybox tar xvf /backup/backup.tar
    data/
    data/sven.txt
    # compare to the original container
    $ sudo docker run --rm --volumes-from DATA -v `pwd`:/backup busybox ls /data
    sven.txt
    

提交回复
热议问题