How to copy a file into or from a running docker container

In this post, we show how to copy a file to a running docker container.  Also we show how to copy an existing file inside a running docker container to your local folder.

 

For copying a file inside a running docker container the command is:

 

docker cp yourfile container-id://path-inside-docker

 

For example to copy a test.txt file into a docker container with the name mydocker in the /var folder the command is :

 

docker cp test.txt mydocker:/var

 

Also for copying a file inside a running docker container to your current directory  the command is:

 

docker cp container-id://path-inside-docker/yourfile .

 

For example to copy  test.txt file inside /var folder in a  docker container with the name mydocker to your local folder, the command is :

 

docker cp  mydocker:/var/test.txt .

 

 

 

 

Leave a Reply

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