📜  docker cp (1)

📅  最后修改于: 2023-12-03 15:30:31.564000             🧑  作者: Mango

Docker CP

Docker CP is a command that allows you to copy files and folders between a Docker container and the host. It is mainly used for transferring data in and out of the container.

Syntax

The syntax of the Docker CP command is as follows:

docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH
docker cp [OPTIONS] SRC_PATH|/CONTAINER:DEST_PATH
Parameters
OPTIONS
  • --archive, -a: The archive mode preserves the timestamps and permissions of the copied files and directories.
  • --follow-link, -L: Follow symbolic links.
  • --no-clobber, -n: Do not overwrite the destination file if it already exists.
  • --quiet, -q: Suppress the progress message shown during the copy process.
CONTAINER

The name or ID of the container to copy the file from or to.

SRC_PATH

The path in the container where the file or directory to be copied is located.

DEST_PATH

The path on the host machine where the file or directory should be copied to.

Examples

To copy a file from a container to the host machine:

docker cp container1:/data/file.txt /home/user/file.txt

To copy a file from the host machine to a container:

docker cp /home/user/file.txt container1:/data/file.txt

To copy a directory from a container to the host machine:

docker cp container1:/data/folder /home/user/folder

To copy a directory from the host machine to a container:

docker cp /home/user/folder container1:/data/folder
Conclusion

Docker CP is a useful command for copying files and directories between the host machine and a container. It provides a simple and efficient way to transfer data in and out of the container.