在Docker容器之间复制数据 [英] Copying data from and to Docker containers

查看:307
本文介绍了在Docker容器之间复制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统上运行了2个docker容器。

I have 2 docker containers running on my system.

我想从主机系统本身将数据从一个容器复制到另一个容器。

I wanted to copy the data from one container to another container from my host system itself.

我知道要将数据从容器复制到主机,我们必须使用

i know that to copy data from container to host we have to use

docker cp <Source path> <container Id>:path in container

中的路径现在我正尝试直接从一个容器中复制数据到另一个,有没有办法做到这一点?

Now i am trying to copy the data directly from one container to another, is there any way to do that ??

我尝试这样做。

docker cp <container-1>:/usr/local/nginx/vishnu/vishtest.txt <container-2>:/home/smadmin/vishnusource/

,但上述命令失败,表明它不受支持。

but the above command failed saying its not supported.

我不应该复制数据到我的本地计算机上,这就是我的要求。

i should not copy the data to my local machine, thats my requirement.

任何人都有一个想法,请先感谢?

anybody have an idea to do this, thanks in advance ?

推荐答案

您应该为此使用

首先,创建卷:

docker volume create --name shared

然后,像这样运行容器:

Then, run containers like this:

docker run -v shared:/shared-folder <container-1>
docker run -v shared:/shared-folder <container-2>

这样, /共享文件夹在这两个容器之间进行同步。

This way, /shared-folder will be synced between these two containers.

了解更多信息此处

希望对您有所帮助

这篇关于在Docker容器之间复制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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