How to Copy Files from Docker Container to Host?

Better Stack Team
Updated on August 1, 2022

Before Docker 1.8, we could only copy files from the container to the host. However, as containers became even more popular, copying files to and from containers has become necessary.

One of the reasons for copying files from the container to the host is to share log files. Or retrieving build artifacts that are built inside the container back into the host.

Keep in mind that copying sensitive information such as files in the /dev/proc/systmpfs is not allowed.

How to copy files from the container to the host?

To copy a file from the container to the host you can use the docker cp command:

 
docker cp <container_id>:/container/path /host/path
  • container_id - Is the name of the container you want to retrieve the file from
  • /container/path - Is the path to the source file within the Docker container
  • /host/path - Is the destination to which the file will be copied.
Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →