如何将码头容器从一台机器复制到另一台机器? [英] How to copy docker volume from one machine to another?
问题描述
我已经在本地机器上创建了postgres的docker卷。
I have created a docker volume for postgres on my local machine.
docker create volume postgres-data
然后我使用这个卷并运行一个码头。
Then I used this volume and run a docker.
docker run -it -v postgres-data:/var/lib/postgresql/9.6/main postgres
之后,我做了一些自动存储在postgres数据中的数据库操作。现在我想将该卷从本地机器复制到另一台远程机器。
After that I did some database operations which got stored automatically in postgres-data. Now I want to copy that volume from my local machine to another remote machine. How to do the same.
注意 - 数据库大小非常大
推荐答案
如果第二台机器启用了SSH,您可以在第一台机器上使用Alpine容器来映射卷,将其捆绑并发送到第二台机器。
If the second machine has SSH enabled you can use an Alpine container on the first machine to map the volume, bundle it up and send it to the second machine.
看起来像这样:
docker run --rm -v <SOURCE_DATA_VOLUME_NAME>:/from alpine ash -c "cd /from ; tar -cf - . " | ssh <TARGET_HOST> 'docker run --rm -i -v <TARGET_DATA_VOLUME_NAME>:/to alpine ash -c "cd /to ; tar -xpvf - "
您需要更改:
- SOURCE_DATA_VOLUME_NAME
- TARGET_HOST
- TARGET_DATA_VOLUME_NAME
或者,您可以尝试使用此帮助脚本 https://github.com/gdiepen/docker-convenience-scripts
Or, you could try using this helper script https://github.com/gdiepen/docker-convenience-scripts
希望这有帮助。
这篇关于如何将码头容器从一台机器复制到另一台机器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!