Linux command
docker-cp 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
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]
说明
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.
参数
- -a, --archive
- Archive mode (copy all uid/gid information).
- -L, --follow-link
- Follow symbolic links in source path.
- -q, --quiet
- Suppress progress output.
FAQ
What is the docker-cp command used for?
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.
How do I run a basic docker-cp example?
Run `docker cp [container]:[/path/to/file] [/local/path]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -a, --archive do in docker-cp?
Archive mode (copy all uid/gid information).