I have a bash script that does a few things, one of which is to docker cp a file to the host.
When I issue that command (without variable expansion) on the command line, the command works. It works with variable expansion on the command line as well. But the command fails in a script; even if that script is on the command line.
The command in the script is:
docker cp ${container_variable}:/some/path/file_name-${date_tag}.zip /host/path
When i try this in a command line script:
for file in `docker exec container ls -1 file_name*`
do
docker cp container:/some/path/$file .
done
I get this (there are four such files that match that wildcard):
Error response from daemon: Could not find the file file_name-1.zip in container container
Error response from daemon: Could not find the file file_name-2.zip in container container
Error response from daemon: Could not find the file file_name-3.zip in container container
Error response from daemon: Could not find the file file_name-4.zip in container container
I just cannot figure out what the issue is here. Any thoughts?
docker cpcommand uses root directory. From the documentation:While
docker execuses current working directory (WORKDIR).So the solution should be to look up what is the workdir in your docker container and add that to your copied path: