DEV Community

Isaias Velasquez
Isaias Velasquez

Posted on

How to copy files from a docker container to host

How to copy files from a docker container to host

Sometimes we just want to know the content of a generated file into some container. And this is the way to do:

First of all, make sure the data you want to copy is in container:

 docker exec -it <container reference> /bin/bash
Enter fullscreen mode Exit fullscreen mode

I strongly suggest you to use /bin/bash instead of sh because sh lacks lots of useful features, like autocomplete, command history.

Then, assured what you need is there, just do it almost like a normal copy:

 sudo docker cp -a <container reference>:<container path> <host path>
    Example:
    sudo docker cp -a 3bbef5e21df:/home/fls/ .
Enter fullscreen mode Exit fullscreen mode

The difference is an ‘-a’ flag which means archive mode. It’ll help you copying with GID|UID information.

That’s all for now.
Thanks for reading!

Top comments (0)