Volumes & Storage

How to Copy Files Between a Docker Container and Host Machine

Copy files or directories between a Docker container and your local host file system without creating a volume mount.

Quick Docker Solution
Safe CommandBeginner
docker cp <container>:/path/in/container /path/on/host
When to use this scenario:You need to extract application logs, a database dump, or a generated build artifact from a container to your desktop.

Step-by-Step Execution Guide

1Copy file from container to local host
docker cp my-container:/var/log/nginx/access.log ./access.log

Downloads access.log from inside my-container to the current local working directory.

2Copy directory from container to host
docker cp my-container:/app/dist ./dist_backup

Recursively copies the entire dist directory from container to local machine.

3Copy local file into a running container
docker cp ./nginx.conf my-container:/etc/nginx/nginx.conf

Injects a local configuration file directly into the container filesystem.

Critical Docker Pitfalls & Precautions

  • β€’docker cp works even if the container is stopped, but cannot copy between two separate remote containers directly.
Frequently Asked Questions

Copy Files (Container <-> Host) - Frequently Asked Questions

Common questions about container isolation, signal handling, and runtime behavior.

Yes! If the destination file already exists on the host or container, docker cp overwrites it without prompting.