如何将数据卷从一个主机传输到另一个主机? [英] How to port data-only volumes from one host to another?

查看:227
本文介绍了如何将数据卷从一个主机传输到另一个主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如关于使用卷的Docker文档中所述,有所谓的


$ b $



基本上这听起来很棒。但是有一件事我不明白。



这些卷(其中显示地映射到主机上的一个文件夹,以便移植性原因,如文档所述)由Docker在主机上的某个内部文件夹( / var / docker / volumes / ... )中创建和管理。



假设我使用了这样一个卷,然后我需要将它从一个主机迁移到另一个主机 - 如何端口的卷? AFAICS它有一个唯一的ID - 我可以去卷并将其根据数据的容器复制到新的主机?如何找出要复制的文件?还有Docker内置了一些我还没有发现的支持?

解决方案

正式的答案现在可以在这里找到:



使用卷共享目录



在备份,还原或迁移数据卷部分中,您具有:



备份:

  sudo docker run --rm --volumes-from DATA  - v $(pwd):/ backup busybox tar cvf /backup/backup.tar / data 




  • - rm :删除容器退出

  • - 卷 - DATA :附加到DATA容器共享的卷

  • -v $(pwd):/ backup :将当前目录绑定到容器中;将tar文件写入

  • busybox :一个简单的图像 - 适合快速维护

  • tar cvf /backup/backup.tar / data :创建/ data目录中所有文件的未压缩tar文件



    • RESTORE:

       #创建一个新的数据容器
      $ sudo docker create -v / data --name DATA2 busybox true
      #将备份文件导入新容器数据卷
      $ sudo docker run --rm - 卷 - 来自DATA2 -v $(pwd):/ backup busybox tar xvf /backup/backup.tar
      data /
      data / sven.txt
      #与原始容器比较
      $ sudo docker run --rm --volumes - from DATA -v`pwd`:/ backup busybox ls / data
      sven.txt


      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 into multiple other containers, no matter whether the data-only container is actually running or not.

      Basically, this sounds awesome. But there is one thing I do not understand.

      These volumes (which do not explicitly map to a folder on the host for portability reasons, as the documentation states) are created and managed by Docker in some internal folder on the host (/var/docker/volumes/…).

      Supposed I use such a volume, and then I need to migrate it from one host to another - how do I port the volume? AFAICS it has a unique ID - can I just go and copy the volume and its according data-only container to a new host? How do I find out which files to copy? Or is there some support built-in to Docker that I did not discover yet?

      解决方案

      The official answer is now available here:

      Sharing Directories using Volumes

      In the "Backup, restore, or migrate data volumes" section you have:

      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
      

      这篇关于如何将数据卷从一个主机传输到另一个主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆