github.com/tompao/docker@v1.9.1/docs/reference/commandline/cp.md (about) 1 <!--[metadata]> 2 +++ 3 title = "cp" 4 description = "The cp command description and usage" 5 keywords = ["copy, container, files, folders"] 6 [menu.main] 7 parent = "smn_cli" 8 +++ 9 <![end-metadata]--> 10 11 # cp 12 13 Usage: docker cp [OPTIONS] CONTAINER:PATH LOCALPATH|- 14 docker cp [OPTIONS] LOCALPATH|- CONTAINER:PATH 15 16 Copy files/folders between a container and the local filesystem 17 18 --help=false Print usage 19 20 In the first synopsis form, the `docker cp` utility copies the contents of 21 `PATH` from the filesystem of `CONTAINER` to the `LOCALPATH` (or stream as 22 a tar archive to `STDOUT` if `-` is specified). 23 24 In the second synopsis form, the contents of `LOCALPATH` (or a tar archive 25 streamed from `STDIN` if `-` is specified) are copied from the local machine to 26 `PATH` in the filesystem of `CONTAINER`. 27 28 You can copy to or from either a running or stopped container. The `PATH` can 29 be a file or directory. The `docker cp` command assumes all `CONTAINER:PATH` 30 values are relative to the `/` (root) directory of the container. This means 31 supplying the initial forward slash is optional; The command sees 32 `compassionate_darwin:/tmp/foo/myfile.txt` and 33 `compassionate_darwin:tmp/foo/myfile.txt` as identical. If a `LOCALPATH` value 34 is not absolute, is it considered relative to the current working directory. 35 36 Behavior is similar to the common Unix utility `cp -a` in that directories are 37 copied recursively with permissions preserved if possible. Ownership is set to 38 the user and primary group on the receiving end of the transfer. For example, 39 files copied to a container will be created with `UID:GID` of the root user. 40 Files copied to the local machine will be created with the `UID:GID` of the 41 user which invoked the `docker cp` command. 42 43 Assuming a path separator of `/`, a first argument of `SRC_PATH` and second 44 argument of `DST_PATH`, the behavior is as follows: 45 46 - `SRC_PATH` specifies a file 47 - `DST_PATH` does not exist 48 - the file is saved to a file created at `DST_PATH` 49 - `DST_PATH` does not exist and ends with `/` 50 - Error condition: the destination directory must exist. 51 - `DST_PATH` exists and is a file 52 - the destination is overwritten with the contents of the source file 53 - `DST_PATH` exists and is a directory 54 - the file is copied into this directory using the basename from 55 `SRC_PATH` 56 - `SRC_PATH` specifies a directory 57 - `DST_PATH` does not exist 58 - `DST_PATH` is created as a directory and the *contents* of the source 59 directory are copied into this directory 60 - `DST_PATH` exists and is a file 61 - Error condition: cannot copy a directory to a file 62 - `DST_PATH` exists and is a directory 63 - `SRC_PATH` does not end with `/.` 64 - the source directory is copied into this directory 65 - `SRC_PATH` does end with `/.` 66 - the *content* of the source directory is copied into this 67 directory 68 69 The command requires `SRC_PATH` and `DST_PATH` to exist according to the above 70 rules. If `SRC_PATH` is local and is a symbolic link, the symbolic link, not 71 the target, is copied. 72 73 A colon (`:`) is used as a delimiter between `CONTAINER` and `PATH`, but `:` 74 could also be in a valid `LOCALPATH`, like `file:name.txt`. This ambiguity is 75 resolved by requiring a `LOCALPATH` with a `:` to be made explicit with a 76 relative or absolute path, for example: 77 78 `/path/to/file:name.txt` or `./file:name.txt` 79 80 It is not possible to copy certain system files such as resources under 81 `/proc`, `/sys`, `/dev`, and mounts created by the user in the container. 82 83 Using `-` as the first argument in place of a `LOCALPATH` will stream the 84 contents of `STDIN` as a tar archive which will be extracted to the `PATH` in 85 the filesystem of the destination container. In this case, `PATH` must specify 86 a directory. 87 88 Using `-` as the second argument in place of a `LOCALPATH` will stream the 89 contents of the resource from the source container as a tar archive to 90 `STDOUT`.