You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal: support wildcards and destination names in docker cp #7710
1 Allow the PATH to contain standard filesystem wildcards, and then expand them on the container side.
2 Allow the HOSTPATH to be the resulting filename if the daemon sends it a single file.
right now
HOSTPATH is a dir, which will even be created for you - rather than the name of the resulting file, and wildcards are not expanded.
tmp $ mkdir sven
tmp $ docker cp sven:/etc/* sven
2014/08/25 14:22:37 Error response from daemon: Could not find the file /etc/* in container sven
tmp $ docker cp sven:/etc/passwd sven/banana
tmp $ ls sven/
banana passwd
tmp $ more sven/*
*** sven/banana: directory ***
tmp $ cd sven
sven $ docker cp sven:/etc/* .
2014/08/25 14:22:23 Error response from daemon: Could not find the file /etc/* in container sven
Reacted by Josh, Plup, Hoat Le, Jason Schroeder, Saulius Žemaitaitis, Magnus Bergmark, Kujiy, Philippe Vaucher, Wadim Kruse, Anton Yanchenko and 155 more
@duglin I am unable to find anything about docker cp supporting wildcards, and am unable to get wildcards working with docker 1.5.0. Can you please point towards me to somewhere with more info?
@duglin docker cp 87ff9d25b53d:/var/log/apache2/access.log .
copies access.log to .
docker cp 87ff9d25b53d:/var/log/apache2/*.log .
returns: ATA[0000] Error response from daemon: Could not find the file /var/log/apache2/*.log in container 87ff9d25b53d
Reacted by Kujiy, Russell Morrisey, Rob Arthur, Chaz Reid, Jack Angers, Timofei Alekperov, Michal Lohniský, Luis Copetti, Andrei Diaconescu, Thomas Mørch and 2 more
One other alternative to achieve what is being asked from this enhancement is to use a dockerignore and docker cp together. I would think that this is far more powerful than equipping docker cp with wildcard support.
As an example, @Aypahyo's use case can be solved using this inverse dockerignore file to whitelist the files of interest.
File: Dockerfile.copy.dockerignore
# ignore everything
*
# except these artifacts of interest
!**/TestResults/*.xml
!**/coverage.opencover.xml
!**/report-task.txt
Essentially, we can use docker to create a context (via daemon sock bind + docker_cli) from inside the final container to suit our needs and copy it to the host via docker cp. Kind of meta!
File: Dockerfile.copy
ARG RESULT_IMAGE
FROM ${RESULT_IMAGE}
WORKDIR /temporary
# copy with same file names
COPY . .
# copy with a different file name and/or different folder
COPY src/run-2021-02-22-01-10/stats.log results/final.txt
This allows to solve any complex "copy the result" scenarios using Docker's ability to tailor a context as needed.
(ex: monorepo build output and test results)
Also not that this addresses both the aspects of the proposal from OP => "wildcards" and "destination names".
I'm no expert with Docker, so I'm looking for any feedback folks might have. Does this approach fall into one of these buckets?
This is a bad idea and we should not use this because _____ (ex: perf, security, etc.).
This does not work for all use cases such as ____.
This is too complex and/or an overkill to solve the problem at hand.
Evidently, after 7.x years, as of 2022, the docker cp command still does not support wildcards. Is it possible to at least give a better error message than ""docker cp" requires exactly 2 arguments" ? That would at least save time vs hunting for status of wildcard support on various forums
Reacted by Andreas Perhab, Goto Hayato, adamency, BenHewins, Andrii Bratanin, NeroMorto, Josh McCullough, K, Arek Kalandyk, Harsh Rawat and 24 more
Evidently, after 7.x years, as of 2022, the docker cp command still does not support wildcards. Is it possible to at least give a better error message than ""docker cp" requires exactly 2 arguments" ? That would at least save time vs hunting for status of wildcard support on various forums
One more year
And we're still there
Whilst I'm getting older
Getting gray hair
Reacted by Jon Goodger, Andreas Perhab, adamency, Lee Hicks, Norbert Schad, Cecilia Xiao, gane01, Jesse Krigelman, Yibo Cai, Vahid and 17 more
It takes the fixed directory in front of the first wildcard, streams it with docker cp CONTAINER:DIR/. - and extracts only the matching entries on the host. Nothing runs inside the container, so it also works on stopped containers and on images without sh or tar, where the docker exec ... tar workaround from this thread fails.
docker-cpg "web:/var/log/app/*.log" logs/
docker-cpg -e old "web:/var/log/**/*.log" logs/ # recursive, skip old/
docker-cpg src/*.py config/ web:/app # several sources in one call
Limits: it reads the whole fixed directory and filters on the host, so web:/**/*.conf streams the entire container filesystem. * and ** skip dotfiles, as in the shell. With a wildcard the destination is always a directory. No container-to-container copy. Tested on Linux with Docker 27 and 28.
Activity
vieux commentedon Aug 27, 2014
This reminds me of #6580
SvenDowideit commentedon Aug 29, 2014
yup, true.
duglin commentedon Sep 30, 2014
I think the wildcard support for this is now done, and #4272 should cover the other bits, so perhaps we can close this?
jessfraz commentedon Sep 30, 2014
closed as dup of #4272
ferrouswheel commentedon Feb 23, 2015
@duglin I am unable to find anything about
docker cpsupporting wildcards, and am unable to get wildcards working with docker 1.5.0. Can you please point towards me to somewhere with more info?gpetz commentedon May 25, 2015
@duglin
docker cp 87ff9d25b53d:/var/log/apache2/access.log .copies access.log to .
docker cp 87ff9d25b53d:/var/log/apache2/*.log .returns: ATA[0000] Error response from daemon: Could not find the file /var/log/apache2/*.log in container 87ff9d25b53d
(Boot2Docker v1.6.2)
duglin commentedon May 25, 2015
You're correct - I think I was mixing up 'docker cp' with "COPY" from Dockerfiles.
However #12858 should do it.
mmarzec commentedon Jun 16, 2016
+1 for this feature
xmhubj commentedon Jun 30, 2016
looking forward to be implemented.
7 remaining items
thaJeztah commentedon Feb 21, 2018
recursive copy is supported;
prepare a container having some files;
copy the contents of
foorecursively;copy
foo, and its contents recursively;courtarro commentedon Jul 10, 2018
A workaround for these limitations, at least with
aufs, is to find the mount point of the container's path and copy files from there:aufsmount point for this container:sudo cat /var/lib/docker/image/aufs/layerdb/mounts/(container_id)/mount-idcd /var/lib/docker/aufs/mnt/(mount_id)michaelarnauts commentedon Mar 11, 2019
Until this is implemented, I use the following workaround by tarring it in the container, and extracting it on the host.
Aypahyo commentedon May 31, 2019
I have a immilar usecase for this.
I have output files that I need to copy.
the names in the container are:
My container is not running so an exec hotfix can not be done.
These commands would find the file in the container when I use an interactive terminal.
Following the pattern:
I would like to write
With a limitation that SRC_PATH and DEST_PATH can only be folder names.
The subfolder structure would be copied from the detected path.
The expected copy result would be
deiga commentedon May 31, 2019
@Aypahyo You can circumvent the "not running" part by commiting the container to an image and running the exec workaround on the new image.
jpereira commentedon Mar 25, 2020
+1 for this feature
vinaygunnam commentedon Feb 22, 2021
One other alternative to achieve what is being asked from this enhancement is to use a
dockerignoreanddocker cptogether. I would think that this is far more powerful than equippingdocker cpwith wildcard support.As an example, @Aypahyo's use case can be solved using this inverse dockerignore file to whitelist the files of interest.
File:
Dockerfile.copy.dockerignoreEssentially, we can use docker to create a context (via daemon sock bind + docker_cli) from inside the final container to suit our needs and copy it to the host via
docker cp. Kind of meta!File:
Dockerfile.copyFinally,
This allows to solve any complex "copy the result" scenarios using Docker's ability to tailor a context as needed.
(ex: monorepo build output and test results)
Also not that this addresses both the aspects of the proposal from OP => "wildcards" and "destination names".
I'm no expert with Docker, so I'm looking for any feedback folks might have. Does this approach fall into one of these buckets?
signalogic commentedon Feb 18, 2022
Evidently, after 7.x years, as of 2022, the docker cp command still does not support wildcards. Is it possible to at least give a better error message than ""docker cp" requires exactly 2 arguments" ? That would at least save time vs hunting for status of wildcard support on various forums
kevinkopf commentedon Feb 12, 2023
One more year
And we're still there
Whilst I'm getting older
Getting gray hair
proof-of-reality commentedon Oct 19, 2023
Wow, this is wild !
debilin commentedon Jan 17, 2024
+1 🙏
iamjjanga-ouo commentedon Apr 23, 2024
I'm also stucked... is there anybody in 2025? ping..
cektom commentedon May 1, 2024
+1 🙏
StiliyanKushev commentedon Jun 28, 2024
+1
Jwrede commentedon Oct 30, 2026
Until
docker cpsupports this, I wrote a small CLI that adds wildcards on top of it (it can also be installed as a Docker CLI plugin,docker cpg): https://github.com/Jwrede/docker-cpgIt takes the fixed directory in front of the first wildcard, streams it with
docker cp CONTAINER:DIR/. -and extracts only the matching entries on the host. Nothing runs inside the container, so it also works on stopped containers and on images withoutshortar, where thedocker exec ... tarworkaround from this thread fails.Limits: it reads the whole fixed directory and filters on the host, so
web:/**/*.confstreams the entire container filesystem.*and**skip dotfiles, as in the shell. With a wildcard the destination is always a directory. No container-to-container copy. Tested on Linux with Docker 27 and 28.