Unable to copy file from Docker container to host

Viewed 33240
$ docker cp maven-container_:xxxx.war /home/wissem/Documents/docker-stage/wildfly-configured/target/

Error response from daemon: lstat

/var/lib/docker/aufs/mnt/afbdc7f4ce3165fb2e6c34929841b9fa911de1978887dd5b9b0804e4f624af2d /xxxx.war: no such file or directory

ERROR: Job failed: exit status 1

3 Answers

I got this error when trying to copy a file under the root folder (seems related to @uthomas's answer).

$ docker cp dreamy_brown:/root/myfile.txt ~
Error: No such container:path: dreamy_brown:/root/myfile.txt

Solution: From within the container I first moved the file to the /tmp folder:

$ mv /root/myfile.txt /tmp

and then I was able to copy it to the host:

$ docker cp dreamy_brown:/tmp/myfile.txt ~

For me it didn't work because of permissions. The file I was trying to copy was owned by postgres user, while the default user seems to be root.

Related