Unable to copy file from Docker container to host
Asked Answered
I

5

12
$ 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

Insuppressible answered 14/8, 2017 at 19:36 Comment(2)
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/target/Acromion
SOLVED : it was my path : docker cp maven-container_:/opt/maven/targe/xxxx.war ....Insuppressible
A
19

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/
Acromion answered 15/8, 2017 at 4:15 Comment(4)
Thsnk. Helped me figure out the problem.Kostroma
doesn't need to be runningPsychic
to copy from an image without running it - create a container with a name. docker create my_image_tag --name my_cont_name; docker cp my_cont_name:/path/file /home/...Accident
Thanks, i was trying to copy out after my test container had exited after finishing tests. I guess the test image is not the same as the instance of docker run, which was a fork of the container image that is lost when it's done?Brubaker
M
10

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 ~
Magritte answered 11/10, 2020 at 14:9 Comment(1)
For anyone else in "Solution" step you have to be inside the container first. I was running inside compose: $docker-compose exec CONTAINER_NAME bash. That brought me to /root/ where I could then move/copy files to tmp as explained.Wardell
R
6

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.

Rosabelle answered 6/7, 2019 at 4:1 Comment(1)
Weird since root user should have access to everything. I tried the suggestion by @Magritte to first move them to /tmp but that is not helping. Plus, the files I am looking at are owned by root, have permissions -rw-r--r--., and are not links. Unless them being root is the problem because the container's default user in my case is something else... Nope, whoami says root.Mi
L
0

I couldn't copy because I was using wildcards.

Didn't work:

docker cp af1f3010481a:/tmp/mydir/* .

Worked:

docker cp af1f3010481a:/tmp/mydir/myfile.txt .
Lura answered 4/5, 2023 at 22:54 Comment(0)
D
0

For me I found that I just need to restart the mysql container.

Device answered 6/1 at 12:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.