Reading Time: < 1 minute

Hi All, this document deals with how to copy a file from container to host machine.
Docker is a set of the platform as service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels.

change the default Docker Root Directory and set SELinux file contexts

change the default Docker Root Directory and set SELinux file contexts

You can copy a file from the host machine to the container by performing the below command,

Get the container ID first.

docker ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                                                 NAMES
677ba0d20c92        asdsad:9.0.1       "/tini -- /bin/sh -c…"   3 weeks ago         Up 9 hours          8052/tcp                                              awx_task

copy the container ID and execute the below copy command.


docker cp testfile.txt container-ID:/foo.txt

This will copy testfile.txt from the host machine to / location of the docker container.

You can copy the below command to copy a file from a docker container to host machine

docker cp container-ID:/testfile.txt newfile.txt

The above command will copy testfile.txt from / location of a docker container to newfile.txt in the current location of the host machine.

© 2019, Techrunnr. All rights reserved.

Questions Answered
Articles Written
Overall Points

Prabhin Prabharkaran

He is Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!!


Leave a Reply