docker-cp
Copy files between container and host
TLDR
View documentation for the original command
SYNOPSIS
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
PARAMETERS
-a, --archive
Archive mode: copy all uid/gid info and preserve file modes (default true)
-L, --follow-link
Follow symbol links in SRC_PATH
-q, --quiet
Suppress progress output
-v, --verbose
Enable verbose mode for detailed output
-h, --help
Print usage information
DESCRIPTION
The docker cp command facilitates efficient file transfer between a running Docker container and the local host machine, or vice versa. It supports copying files, directories, or streams (using - for stdin/stdout) with options for preserving permissions and following symlinks.
Use cases include debugging by extracting logs or configs from containers, injecting scripts or data into running services, or backing up container state without stopping the container. Paths for containers must be prefixed with CONTAINER:, e.g., mycontainer:/app/data, while host paths are absolute or relative.
By default, it operates in archive mode (-a), preserving user/group IDs and file modes. Multiple source paths can be copied to a single directory destination. Progress is shown unless suppressed with -q. Verbose output (-v) details each file operation.
This command requires the Docker daemon to be running and access to the specified container ID or name. It does not support direct copies between two containers; use docker exec or temporary mounts instead. Ideal for ephemeral data movement in containerized workflows.
CAVEATS
Cannot copy directly between containers; use host as intermediary or docker exec. Host paths must be accessible to Docker daemon. Permissions may require root or Docker group membership. No support for remote URLs except stdin/stdout via -. Large directories can be slow without compression.
EXAMPLES
docker cp mycontainer:/app/log.txt . — Copy log from container to current dir.
docker cp dir/ mycontainer:/backup/ — Copy host dir to container.
docker cp mycontainer:/data.tar.gz - | gzip -d | tar x — Stream and extract.
HISTORY
Introduced in Docker 0.7.0 (2014) as part of core CLI for container-host file ops; evolved with archive mode in 1.8.0 and symlink support later. Remains stable in Docker 27+ with minor UX tweaks.


