How to copy files from host to Docker container

In this article, we will see how to copy files from host to Docker container step by step.

We can copy files from host to docker container using docker cp command. Using the same cp command, we can docker container to docker host.

Copy files from host to Docker container

Syntax to copy files from host to Docker container:

sudo docker cp source_path container_id/name:destination_path

Examples:

1. Copy file named “r2schools.txt” to docker container’s directory root:

sudo docker cp /home/r2schools/dd/r2schools.txt webapp1:/root/

How to copy files from host to Docker container

Where
/home/r2schools/dd/r2schools.txt is the file from host
webapp1:/root/ is the taget or destionation path
webapp1 is the docker container name.

2. Now, copy entire directory from host to docker contiainer using the below command.

sudo docker cp /home/r2schools/dd/ webapp1:/root/

So in this article, we have how to copy file or directory from host to Docker container with examples.

Same explained in the below video with examples:

Leave a Reply

Your email address will not be published. Required fields are marked *