So I have a docker container with .txt and .csv files in it. I need to copy these to host. But I only need to copy files .txt files. The command sudo docker cp -a env1_1:/path/*.txt .
does not seem to work. Is copying files of a specific types possible using docker cp? I am unable to find any alternatives for now.
Any suggestions?
Thanks.
Indeed,
docker cp
does not support glob patterns, and as an aside, container paths are absolute:However, one may devise a workaround, relying on
docker exec
, and a manually crafted shell command relying on thetar
command on both sides (assuming it is available in the image):or if need be:
Here, the special filename
-
denotes STDOUT (or respectively STDIN).Usual disclaimer: the final
tar
command will overwrite without further notice the selected files in the current folder (or/dest/path
in the second example).