Copying files To &From Running Docker Container.

Many times we wanted to copy a file to the container or copy our work to & from the container. Using a docker volume and bound mounts can be a good way but what if you forget to attach a volume to the container?

Well, when you caught up in that situation and you do not want to use volume for single copy operation and want to do at runtime. The solution to this is single docker Command:

Docker cp: Copy files/folders between a container and the local filesystem, Just check the docker cp — help:

C:\Users\anand> docker cp — help


Copy files/folders between a container and the local filesystem

-a, — archive Archive mode (copy all uid/gid information)
-L, — follow-link Always follow symbol link in SRC_PATH

Step 1: Run a sample Nginx image:

Run an Nginx image
Running container

Step 2: Now I will create a single text file so that I can copy it into a container

Step 3: Copying this file into the Running container:

Step4: Done! Now you can go inside the container and see the file is copied at the destination:

or you can see it from the browser with this path:

You can do this vice-versa as well…!

Hope this simple docker command helps you :) follow me for such short and crisp docker article!

Software QA Engineer who do QA and DevOps stuff

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store