📅  最后修改于: 2023-12-03 15:30:31.564000             🧑  作者: Mango
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.
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
--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.The name or ID of the container to copy the file from or to.
The path in the container where the file or directory to be copied is located.
The path on the host machine where the file or directory should be copied to.
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
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.