Search code examples
mongodbdockercontainers

Copy folder with wildcard from docker container to host


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 ?


Solution

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

    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.

    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/