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
docker exec
Runs a new command inside an already running container. Commonly used for shells, debugging, or one-off maintenance tasks.
docker volume
Manages persistent named volumes for containers — create, list, inspect, remove, and prune. Named volumes survive container removal and are the recommended storage mechanism over bind mounts for stateful data.
docker run
Creates and starts a new container from a specified image in a single step. This is the primary command for launching workloads and supports extensive configuration for networking, storage, and process control.
docker inspect
Returns low-level JSON metadata about Docker objects — containers, images, networks, volumes, and more. Supports Go template formatting for extracting specific fields.
docker ps
Lists containers along with their status, ports, and identifiers. By default it shows only running containers unless -a is passed.
← All Docker commands · Docker vs Kubernetes · Docker vs VMs