containers

docker cp

Copies files and directories between a container's filesystem and the host. Works on both running and stopped containers.

docker cp [OPTIONS] SRC_PATH|CONTAINER:SRC_PATH DEST_PATH|CONTAINER:DEST_PATH

Common flags

Flag Purpose
-a, --archive Preserve UID/GID information from the source
-L, --follow-link Follow symbolic links in SRC_PATH
-q, --quiet Suppress progress output

Examples

docker cp web:/etc/nginx/nginx.conf ./nginx.conf

Pull config out of a container

docker cp ./patch.sh web:/tmp/patch.sh

Copy a script into a container

docker cp db:/var/lib/postgresql/data ./backup

Recursive directory copy

docker cp - web:/app < archive.tar

Stream a tar archive into a container

Gotcha

Trailing slash rules mirror rsync — cp SRC/. DEST copies contents, while cp SRC DEST copies the directory itself. On Windows hosts, path drive letters (C:\) can conflict with the CONTAINER: syntax; use quotes or WSL paths.

Related commands

← All Docker commands · Docker vs Kubernetes · Docker vs VMs