EDDYMENS

Last updated 2024-01-13 10:40:53

How To Copy Files/folders Between A Docker Container And Your Local Filesystem

Table of contents

Copy from your local system to a container (Local -> Container)


Command structure

$ docker cp <source_path> <container_id>:<destination_path>

Here is an example of copying files from your local machine to a running container:

Example

$ docker cp index.html 2347:/var/www/index.html

This will copy a file named index.html within your current path to the folder /var/www in a container with the ID 2347.

Copying from a container to your local system (Container -> Local)


Command structure

$ docker cp <container_id>:<source_path> <destination_path>

Example

$ docker cp 2347:/var/www/html/data/ /home/user/archive/data

The command above copies the data folder located at /var/www/html/ within the container with the ID 2347 to a data that will be created within your local directory /home/user/archive/.

If you are unsure of the container path, use docker -it exec bin/bash to gain shell access to the container then navigate to figure out the path you need.

Getting the container ID

The docker command docker ps lists out details of every running container.

Here is another article you might like 😊 "Diary Of Insights: A Documentation Of My Discoveries"