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.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github