Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 292
Abdelrahman Elkady Avatar asked Mar 04 '16 21:03

Abdelrahman Elkady


People also ask

How do I copy a directory from docker to local container?

The docker cp utility copies the contents of SRC_PATH to the DEST_PATH . You can copy from the container's file system to the local machine or the reverse, from the local filesystem to the container. If - is specified for either the SRC_PATH or DEST_PATH , you can also stream a tar archive from STDIN or to STDOUT .

How do I copy a directory from container to host?

To summarize, follow these steps to copy a file from a Docker container to a host machine: Obtain the name or id of the Docker container. Issue the docker cp command and reference the container name or id. The first parameter of the docker copy command is the path to the file inside the container.

How do I copy multiple files from docker container to local machine?

Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|- docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH Copy files/folders between a container and the local filesystem Use '-' as the source to read a tar archive from stdin and extract it to a directory destination in a container.

How do I copy a folder using docker cp?

If you want to copy the /tmp/foo directory from a container to the existing /tmp directory on your host. If you run docker cp in your (home) directory on the local host: $ docker cp compassionate_darwin:tmp/foo /tmp Docker creates a /tmp/foo directory on your host.


1 Answers

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

$ docker exec <id> bash -c "mkdir -p /extract; cp -f /path/to/fileset* /extract" $ docker cp <id>:/extract/. . 
like image 190
user9334670 Avatar answered Sep 16 '22 23:09

user9334670