Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to copy file from Docker container to host

$ 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

like image 657
Mahjoub Wissem Avatar asked Aug 14 '17 19:08

Mahjoub Wissem


People also ask

How do I copy a file from docker container to local host?

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. The second parameter of the docker copy command is the location to save the file on the host.

Can I copy docker volume to another host?

Transfer a volume to another Docker hostFrom the extension, you can specify both the destination host the local volume copied to (for example, [email protected] ) and the destination volume. > SSH must be enabled and configured between the source and destination Docker hosts.


3 Answers

You need to copy from a running instance and not an image. So I assume maven-container_ is a name of the container your had launched and not a image. Also use complete path after :,

docker cp maven-container_:/path/inside/container/xxxx.war /home/wissem/Documents/docker-stage/wildfly-configured/targe‌​t/
like image 179
Tarun Lalwani Avatar answered Oct 19 '22 15:10

Tarun Lalwani


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 ~
like image 45
asherbret Avatar answered Oct 19 '22 15:10

asherbret


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.

like image 5
uthomas Avatar answered Oct 19 '22 16:10

uthomas