Copy Files And Folders to a Running Docker Container

In this blog post, we will learn how to copy files or folders from the container host to a running Linux container.

Copy files to a running can be handy sometimes and prevent downtime when there is a need to test a new configuration.

Docker CP

For this purpose, the Docker CLI gives us the option to copy files and folders from our container host file systems directly into the container’s file system without any disruption.

In the following example, I will do the following. Create a Linux container with Ubuntu. Copy a single file called to the container’s /etc. folder.

docker run --name deploy01 -ti -d ubuntu:latest /bin/bash
docker container cp deploy01:/etc

To check that the file was copied to the container, I will use the attach command to log in to the container.

docker container attach deploy01

To view the etc. folder I will run.

ls /etc

1 thought on “Copy Files And Folders to a Running Docker Container”

Comments are closed.