13

I am trying to copy file from docker to host using the below command,

docker cp <container_name>:<file FQN> ./

But getting the below error,

Error response from daemon: not a directory

As verified, the file name and container name are valid. Note: Using Docker in Mac

5 Answers 5

8

Thanks for all the answers. After a bit of struggle found out that the error message was not actually directly related to the docker cp command.

The scenario was, I ran the docker with the link to a local file. When the docker was running I deleted it. Then the file got created as a folder somehow (Probably, when I restarted the docker).

And whenever I am executing some command, the docker was giving me that error. Then once I created the file the error disappeared.

1
  • 2
    +1 - In my case, I was using docker-compose with host files mapped via volumes. Deleting the file in the host system appeared to cause docker cp to make a folder in it's place (with the same name) on the host system and then throw the error. Deleting the directory and touching the file on the host restored the mapping, fixed the error and let me get files out again. Thanks!
    – n0741337
    Apr 17, 2018 at 21:26
1

It seems your command is correct. You please try like the below from your local machine not from inside the container. sometimes unfortunately if we run this command with in the container we will get this kind of errors.

docker cp [container_name]:[docker dir abs path] [host dir path]

Hope it will help you.

1

Here is a full example on how to copy a file:

$ docker run -it ubuntu /bin/bash 
root@9fc8a1af7f23:/# 
root@9fc8a1af7f23:/# ll 
total 72
drwxr-xr-x  34 root root 4096 Jul 13 21:51 ./
drwxr-xr-x  34 root root 4096 Jul 13 21:51 ../
-rwxr-xr-x   1 root root    0 Jul 13 21:51 .dockerenv*
drwxr-xr-x   2 root root 4096 Feb 14 23:29 bin/
drwxr-xr-x   2 root root 4096 Apr 12  2016 boot/
drwxr-xr-x   5 root root  360 Jul 13 21:51 dev/
drwxr-xr-x  45 root root 4096 Jul 13 21:51 etc/
drwxr-xr-x   2 root root 4096 Apr 12  2016 home/
drwxr-xr-x   8 root root 4096 Sep 13  2015 lib/
drwxr-xr-x   2 root root 4096 Feb 14 23:29 lib64/
drwxr-xr-x   2 root root 4096 Feb 14 23:28 media/
drwxr-xr-x   2 root root 4096 Feb 14 23:28 mnt/
drwxr-xr-x   2 root root 4096 Feb 14 23:28 opt/
dr-xr-xr-x 288 root root    0 Jul 13 21:51 proc/
drwx------   2 root root 4096 Feb 14 23:29 root/
drwxr-xr-x   6 root root 4096 Feb 27 19:41 run/
drwxr-xr-x   2 root root 4096 Feb 27 19:41 sbin/
drwxr-xr-x   2 root root 4096 Feb 14 23:28 srv/
dr-xr-xr-x  13 root root    0 Jul 13 21:51 sys/
drwxrwxrwt   2 root root 4096 Feb 14 23:29 tmp/
drwxr-xr-x  11 root root 4096 Feb 27 19:41 usr/
drwxr-xr-x  13 root root 4096 Feb 27 19:41 var/
root@9fc8a1af7f23:/# cd tmp/
root@9fc8a1af7f23:/tmp# ls 
root@9fc8a1af7f23:/tmp# echo "hello docker" > docker_test.txt
root@9fc8a1af7f23:/tmp# cat docker_test.txt 
hello docker
root@9fc8a1af7f23:/tmp# 

Then, in another terminal

dali@dali-X550JK:~$ docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
9fc8a1af7f23        ubuntu              "/bin/bash"         2 minutes ago       Up 2 minutes                            fervent_hodgkin
dali@dali-X550JK:~$ docker cp fervent_hodgkin:/tmp/docker_test.txt /tmp/
dali@dali-X550JK:~$ cat /tmp/docker_test.txt 
hello docker
dali@dali-X550JK:~$ 

Please follow these instruction, make sure your don't have typo in the file paths, otherwise share a reproducible error.

1

This error also appears when trying to copy a file that is actually a volume in the container, but the file has been deleted on the host.

-2

This is simply an error in the path you want to copy. You may not believe it, but that it is.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.