Docker卷:备份 [英] Docker volume: backup

查看:241
本文介绍了Docker卷:备份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个卷容器。另外还有一个容器从容器装载到en。



卷容器:

  docker run -d --name nexus-data nexus:1.0 echoNexus的数据专用容器

我的Nexus容器:

  docker run -d -p 8443:8443 -p 8081:8081 --name nexus --restart = always --volumes-from nexus-data nexus:1.0 

所以这是工作精细。我可以删除并重新创建我的nexus容器,而不会丢失数据。卷容器(不处于运行状态)正在保存数据。



但这种方法的瓶颈是卷容器。当我意外删除这个容器时,所有的数据都没有了。
这可以非常快地发生,因为一些有用的命令将删除停止的容器也将删除卷容器。



所以我想为我的卷创建备份,容器。
我尝试的方法:

  $ docker cp nexus:/ this / folder / / home / ubuntu /文件夹

 code> $ docker import nexus> /home/ubuntu/backup.tar 

所以我的主目录中有一个文件夹和一个.tar 。
现在我想知道导入其中一个备份的正确方法是什么?



我阅读了关于 docker export 命令创建一个新图像,但是我不喜欢这种方法,因为我的备份文件夹很大。

解决方案

只需不要使用数据卷容器:因为docker 1.9,你可以使用 docker volume create 。 Docker现在有一个卷命令


以下示例还创建了 my-named-volume volume,这次使用 docker volume创建命令。




  $ docker volume create --name my-named-volume -o size = 20GB 
$ docker run -d -P \
-v my-named -volume:/ opt / webapp \
--name web training / webapp python app.py

这些卷被命名,由docker volume ls列出,您可以备份 / var / lib / docker / volumes



对于数据卷容器,您需要记住该容器中数据的路径( docker inspect -f'{{(index .Mounts 0).Source}} ),将其写入文件,并在创建新的数据卷包含时使用该路径r。

我曾经用 updateDataContainerPath.sh 。请参阅重新附加孤儿泊坞站卷



我不需要从Docker 1.9开始的卷曲机制,并命名卷。


I have created a volume container. And a container which mounts to en from the volume container.

Volume container:

docker run -d --name nexus-data nexus:1.0 echo "data-only container for Nexus"

My Nexus container:

docker run -d -p 8443:8443 -p 8081:8081  --name nexus --restart=always --volumes-from nexus-data nexus:1.0

So this is working fine. I'm able to delete and recreate my nexus-container without losing data. The volume container (which isn't in running state) is saving the data.

But the bottleneck of this approach is the volume-container. When I accidentally delete this container, all the data is gone. This can happen pretty fast because some useful commands which will delete stopped containers will also delete the volume containers.

So I want to create backups for my volume-containers. I tried to ways:

$ docker cp nexus:/this/folder/ /home/ubuntu/backup-folder

And

$ docker import nexus > /home/ubuntu/backup.tar

So I have one folder and one .tar in my home directory. Now I want to know what's the right approach to import one of these backups?

I read about the docker export command to create a 'new image' but I don't like this approach because my backup folder is pretty big.

解决方案

Simply don't use data volume container: since docker 1.9, you can use docker volume create instead. Docker now has volume commands.

The following example also creates the my-named-volume volume, this time using the docker volume create command.

$ docker volume create --name my-named-volume -o size=20GB
$ docker run -d -P \
  -v my-named-volume:/opt/webapp \
  --name web training/webapp python app.py

Those volumes are named, listed by docker volume ls, and you can backup /var/lib/docker/volumes.

With data volume container, you would need to memorize the path of the data within that container (docker inspect -f '{{ (index .Mounts 0).Source }}), write it to a file, and use that path when you create a new data volume container.
I used to do that with updateDataContainerPath.sh. See "Reattaching orphaned docker volumes".

I do not need that convoluted mechanism since docker 1.9 and named volumes.

这篇关于Docker卷:备份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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