Copy folder with wildcard from docker container to host

有些话、适合烂在心里 提交于 2019-12-06 18:27:52

问题


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 :

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

Is there any workaround to use wildcards with cp command ?


回答1:


You can create the mongo dump files into a folder inside the container and then copy the folder: this is a workaround.

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

I think the best way to handle what you want to do is to use docker volumes, so you can directly save the files from the container into your host folder without using any other command: https://docs.docker.com/engine/userguide/containers/dockervolumes/




回答2:


I had a similar problem, and had to solve it in two steps:

$ docker exec <id> bash -c "mkdir /extract; mv /path/to/fileset* /extract"
$ docker cp <id>:/extract .


来源:https://stackoverflow.com/questions/35806102/copy-folder-with-wildcard-from-docker-container-to-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!