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.
docker cp <container>:/path/in/container /path/on/hostStep-by-Step Execution Guide
docker cp my-container:/var/log/nginx/access.log ./access.logDownloads access.log from inside my-container to the current local working directory.
docker cp my-container:/app/dist ./dist_backupRecursively copies the entire dist directory from container to local machine.
docker cp ./nginx.conf my-container:/etc/nginx/nginx.confInjects 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.
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.
Related Docker Command Guides
Browse All Docker RecipesOpen an interactive terminal shell session inside a live running Docker container to inspect files, debug processes, or test network connectivity.
Reclaim gigabytes of hard drive space by removing stopped containers, unused networks, dangling images, and build caches.
Instantly stop all active containers and optionally remove them with a single command.
Understand the fundamental differences between ENTRYPOINT and CMD directives and how to combine them for flexible container CLIs.
Inspect stdout and stderr output from containers with timestamps, tail line limits, and live streaming.
Best practices for copying files into Docker images. Why COPY is almost always preferred over ADD.