Copy file into docker container instance

Copy file into a Docker Container is a very easy task by command. Let us view step by step process to copy files into Docker Container.

Step 1:

Get your docker container id.

sudo docker ps

This will show a list of all Docker Containers with id.

Step 2:

Use the copy command to copy a file into Docker Container.

sudo docker cp <Source file path of your Local Machine> <Docker Container ID>:<Docker Container Path>

sudo docker cp /Users/john/Downloads/requirement.txt 5e170b83bfce:/

Step 3:

View file in the Docker Container by connecting to docker instance. First, need to open terminal of Docker Container

docker exec -it 5e170b83bfce /bin/sh

Now on docker terminal change directory to root and view files.

cd /
ls -l

You will see your file there.

Now you can exit from Docker Terminal.

exit

 

Keywords: