docker-cp

copy files between containers and the host

TLDR

Copy file from container to host
$ docker cp [container]:[/path/to/file] [/local/path]
Copy file from host to container
$ docker cp [/local/file] [container]:[/path/in/container]
Copy directory recursively
$ docker cp [container]:[/path/to/dir] [/local/dir]
Copy preserving ownership
$ docker cp -a [container]:[/path] [/local/path]

SYNOPSIS

docker cp [options] container:srcpath destpathdocker cp [options] srcpath container:destpath

DESCRIPTION

docker cp copies files or directories between a container's filesystem and the local host filesystem, functioning bidirectionally for both container-to-host and host-to-container transfers. This command works with both running and stopped containers, making it useful for extracting logs, injecting configuration files, or backing up data.The command uses tar internally for efficient transfer, streaming data between the container and host. Archive mode (-a) preserves file ownership and permissions, which is important when copying system files or maintaining consistent file attributes.Unlike volume mounts which are configured at container creation, docker cp enables ad-hoc file transfer at any time during a container's lifecycle.

PARAMETERS

-a, --archive

Archive mode (copy all uid/gid information).
-L, --follow-link
Follow symbolic links in source path.
-q, --quiet
Suppress progress output.

INSTALL

sudo apt install docker-cli
sudo dnf install docker-cli
sudo pacman -S docker
sudo apk add docker-cli
sudo zypper install docker
brew install docker
nix profile install nixpkgs#docker

SEE ALSO

docker-container-cp(1), docker(1)

RESOURCES

Source code · Documentation