在其中创建具有预先存在的数据的Docker卷 [英] Create Docker volume with preexisting data in it

查看:122
本文介绍了在其中创建具有预先存在的数据的Docker卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MySQL映像,我启动一个容器。
我设置了dbs,导入sql-dump文件,并在创建容器时创建用户。



当我在容器上工作时,我创建存储在MySQL中的各种数据。



我想将这些额外的数据保存在数据卷容器[DVC]中,所以我可以给DVC一个同事,并从我停止的地方继续。



事情是他也会启动MySQL容器,初始过程将从头开始重复。



正如我所看到的,如果我挂载[ - volumes-from ]从[...]的卷[ / etc / mysql / var / lib / mysql ] DVC,已经存在的数据将被覆盖,不可读。



是否可以使用具有已有数据的目录的卷?

解决方案

简短的答案是否定的,但这是因为您已经错过了您的容器。

这就是为什么你的图片不应该包含静态数据。将静态的东西保存在图像中,并在数据容器中保留动态的东西。 (和启动脚本动态评估任何需要它的东西)



您可以使用一个 docker cp 来提取将文件放入一个数据容器中,或者将一个本地文件系统安装到一个新的安装点,然后使用 tar / rsync docker exec ,然后重新安装 - 但实际上我建议重建您的图像,以始终使用数据容器的数据。


I have a MySQL image that I launch a container from. I set up dbs , import sql-dump files and create users every time the container is created.

When I work on the container I create various data that are stored in MySQL.

I would like to save these extra data in a data volume container [DVC] so I could give the DVC to a colleague and continue from where I stopped.

The thing is that he will also launch a MySQL container and the initial procedure will be repeated from scratch.

As I have read, if I mount [--volumes-from] the volumes [/etc/mysql and /var/lib/mysql] from the DVC , the already existing data will be covered and will not be readable.

Is it possible to use volumes with directories that already have data in them?

解决方案

The short answer is no, but that's because you've gone down the wrong road with your container.

This is why your image shouldn't include static data. Keep the static things in the image, and they dynamic things in a data container. (And a startup script to dynamically evaluate anything that needs it)

You can probably use a docker cp to extract the files into a data container for a one off - or just passthrough mount a local filesystem, to a new mountpoint, and just use tar / rsync with docker exec before re-mounting - but actually I'd suggest rebuild your image to always use a data container for it's data.

这篇关于在其中创建具有预先存在的数据的Docker卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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