简体   繁体   English

导出和导入docker数据容器

[英]export and import docker data containers

I am new to docker and I have a problem when it comes to shipping data containers. 我是docker的新手,在运输数据容器方面我遇到了问题。 Ok, usually we ship images and users can start as may containers from this image as the want, right? 好的,通常我们发送图像,用户可以像这个图像中的容器一样启动,对吧?

Now I want to ship some data too - so I have made a data container so: 现在我也想发布一些数据 - 所以我创建了一个数据容器:

docker create -v /dbdata --name dbdata phusion/baseimage

Next I simply started a bash and inserted some data into my data container 接下来,我只是启动了一个bash并将一些数据插入到我的数据容器中

docker run --volumes-from dbdata -i -t phusion/baseimage /bin/bash
echo "foo" > /dbdata/bar.txt
exit

Now I want to allow my team members to use the same data (offline), so I would like to "send" my data container to them. 现在我想让我的团队成员使用相同的数据(离线),所以我想将“数据容器”“发送”给他们。 Therefore I have used 所以我用过

docker export dbdata > /tmp/cool_data.tar

But when I re import this with 但是当我重新导入它时

cat /tmp/data.tar | sudo docker import - dbdata2

I can not use this "container" because it seems to be an image 我不能使用这个“容器”,因为它似乎是一个图像

docker run --volumes-from dbdata2 -i -t phusion/baseimage /bin/bash
FATA[0000] Error response from daemon: Container dbdata2 not found. Impossible to mount its volumes 

How do I export and import data containers correctly? 如何正确导出和导入数据容器?

You need to make a container out of this image first. 您需要先从此图像中创建一个容器。 Run this: 运行这个:

docker create -v /dbdata --name dbdata2 dbdata2

For more details, check out Creating and mounting Data Volume Containers 有关更多详细信息,请查看创建和装载数据卷容器

You can't export and import data in volumes like this - volumes are simply not included in export/import. 您无法在此类卷中导出和导入数据 - 卷只是不包含在导出/导入中。

You don't need to do this however - just zip or tar the directories the volumes are mapped to and send to your colleagues. 但是您不需要这样做 - 只需压缩或tar tar卷映射到的目录并发送给您的同事。 They can then make their own data containers using those files. 然后,他们可以使用这些文件创建自己的数据容器。

You may also want to look at flocker , which can help you migrate containers and data. 您可能还想查看flocker ,它可以帮助您迁移容器和数据。

I'm having good luck with the following Dockerfile: 我对以下Dockerfile运气不错:

from scratch

ADD install_theGreatSoftwarePkg /install
VOLUME /install

Then I do a build and create: 然后我做一个构建并创建:

docker build -t greatSoftwareInstallImage .
docker create -t --name=greatSoftwareMedia greatSoftwareInstallImage /bin/true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM