LinuxCommandLibrary

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
Copy file from host to container
$ docker cp [/local/file] [container]:[/path/in/container]
copy
Copy directory recursively
$ docker cp [container]:[/path/to/dir] [/local/dir]
copy
Copy preserving ownership
$ docker cp -a [container]:[/path] [/local/path]
copy

SYNOPSIS

docker cp [options] container:srcpath destpath
docker 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.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community