将带有通配符的文件夹从 docker 容器复制到主机 [英] Copy folder with wildcard from docker container to host

查看:23
本文介绍了将带有通配符的文件夹从 docker 容器复制到主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建备份脚本以将 mongodb 转储到容器内,我需要将文件夹复制到容器外,Docker cp 似乎不适用于通配符:

Creating a backup script to dump mongodb inside a container, I need to copy the folder outside the container, Docker cp doesn't seem to work with wildcards :

docker cp mongodb:mongo_dump_* .

在终端中抛出以下内容:

The following is thrown in the terminal :

来自守护进程的错误响应:lstat/var/lib/docker/aufs/mnt/SomeHash/mongo_dump_*: no such file或目录

Error response from daemon: lstat /var/lib/docker/aufs/mnt/SomeHash/mongo_dump_*: no such file or directory

在 cp 命令中使用通配符有什么解决方法吗?

Is there any workaround to use wildcards with cp command ?

推荐答案

似乎没有办法在 docker cp 命令中使用通配符 https://github.com/docker/docker/issues/7710.

It seems there is no way yet to use wildcards with the docker cp command https://github.com/docker/docker/issues/7710.

您可以将 mongo 转储文件创建到容器内的文件夹中,然后复制该文件夹,详见另一个答案此处.

You can create the mongo dump files into a folder inside the container and then copy the folder, as detailed on the other answer here.

如果您有一个大型数据集和/或需要经常进行操作,最好的处理方法是使用 docker 卷,这样您就可以直接将文件从容器访问到您的主机文件夹,而无需使用任何其他命令:https://docs.docker.com/engine/userguide/containers/dockervolumes/

If you have a large dataset and/or need to do the operation often, the best way to handle that is to use docker volumes, so you can directly access the files from the container into your host folder without using any other command: https://docs.docker.com/engine/userguide/containers/dockervolumes/

这篇关于将带有通配符的文件夹从 docker 容器复制到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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