如何将纯数据卷从一台主机移植到另一台主机? [英] How to port data-only volumes from one host to another?

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

问题描述

如关于使用卷的Docker文档中所述,有一个所谓的概念data-only 容器,它提供了一个可以挂载到多个其他容器中的卷,无论该 data-only 容器是否实际运行.

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.

这些卷(出于可移植性的原因,它们不会显式映射到主机上的文件夹,如文档所述)由 Docker 在主机上的某个内部文件夹中创建和管理(/var/docker/volumes/...).

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/…).

假设我使用了这样一个卷,然后我需要将它从一台主机迁移到另一台主机 - 我该如何移植该卷?AFAICS 它有一个唯一的 ID - 我可以直接将卷及其相应的仅数据容器复制到新主机吗?如何找出要复制的文件?或者是否有一些我还没有发现的内置于 Docker 的支持?

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?

推荐答案

官方答案在 "备份、恢复或迁移数据卷":

备份:

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

  • --rm:容器退出时移除
  • --volumes-from DATA:附加到DATA容器共享的volumes
  • -v $(pwd):/backup:绑定挂载当前目录到容器中;将tar文件写入
  • busybox:一个简单的小图像 - 适合快速维护
  • tar cvf/backup/backup.tar/data:创建/data目录下所有文件的解压tar文件
    • --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
    • 恢复:

      # 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天全站免登陆