How to Copy files from Docker Container to Host and ViceVersa

How to Copy files from Docker Container to Host and ViceVersa

in this article i will show you how to copy the files from docker container to host machine and vice-versa. to copy the files from docker container to host or host to container we use docker cp command.

Copy files from Docker Container to Host

docker cp <containerId>:/file/path/in/container/   /file/path/in/host

using above docker cp command we can copy the files from docker container to host machine.

$ docker ps
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS         PORTS                NAMES
7b0de611b7f0        webserver-image:v1   "/docker-entrypoint.…"   33 seconds ago      Up 24 seconds 0.0.0.0:80->80/tcp   zealous_mahavira

$ docker cp 7b0de611b7f0:/usr/share/nginx/html  /home/devops/index.html

Copy files from Host to Docker Container

docker cp  /file/path/in/host   <containerId>:/file/path/in/container/

using above command we can copy the files from host machine to docker container.

$ docker ps

CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS         PORTS                NAMES
7b0de611b7f0        webserver-image:v1   "/docker-entrypoint.…"   33 seconds ago      Up 24 seconds 0.0.0.0:80->80/tcp   zealous_mahavira

$ docker cp /home/devops/index.html 7b0de611b7f0:/usr/share/nginx/html

Other Resources:

You can also read docker documentation on docker cp command

Leave a Reply

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