Docker: Cp Command – Copy File ( To | From ) Container

The docker cp command serves for copying files and folders between Docker container and a host machine.

It is possible to copy a file or folder from host to container as well as from container to host.

In the examples below i am coping the files but the syntax for copying folders is the same.

Cool Tip: How do i list ( running | stopped | all ) Docker containers! Read More →

Docker Cp Command

Find out a container’s name or ID using the docker ps command:

$ docker ps
72ca2488b353  my_image          X hours ago  Up X hours         my_container

Copy a file from host to container:

$ docker cp foo.txt 72ca2488b353:/foo.txt

Copy a file from Docker container to host:

$ docker cp 72ca2488b353:/foo.txt foo.txt

2 Replies to “Docker: Cp Command – Copy File ( To | From ) Container”

  1. Thanks for the info, using this command, I am able to copy from container to my host

  2. Thanks.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.