github.com/ncdc/docker@v0.10.1-0.20160129113957-6c6729ef5b74/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:SRC_PATH DEST_PATH | - 14 docker cp [OPTIONS] SRC_PATH | - CONTAINER:DEST_PATH 15 16 Copy files/folders between a container and the local filesystem 17 18 -L, --follow-link Always follow symbol link in SRC_PATH 19 --help Print usage 20 21 The `docker cp` utility copies the contents of `SRC_PATH` to the `DEST_PATH`. 22 You can copy from the container's file system to the local machine or the 23 reverse, from the local filesystem to the container. If `-` is specified for 24 either the `SRC_PATH` or `DEST_PATH`, you can also stream a tar archive from 25 `STDIN` or to `STDOUT`. The `CONTAINER` can be a running or stopped container. 26 The `SRC_PATH` or `DEST_PATH` be a file or directory. 27 28 The `docker cp` command assumes container paths are relative to the container's 29 `/` (root) directory. This means supplying the initial forward slash is optional; 30 The command sees `compassionate_darwin:/tmp/foo/myfile.txt` and 31 `compassionate_darwin:tmp/foo/myfile.txt` as identical. Local machine paths can 32 be an absolute or relative value. The command interprets a local machine's 33 relative paths as relative to the current working directory where `docker cp` is 34 run. 35 36 The `cp` command behaves like the Unix `cp -a` command in that directories are 37 copied recursively with permissions preserved if possible. Ownership is set to 38 the user and primary group at the destination. For example, files copied to a 39 container are created with `UID:GID` of the root user. Files copied to the local 40 machine are created with the `UID:GID` of the user which invoked the `docker cp` 41 command. If you specify the `-L` option, `docker cp` follows any symbolic link 42 in the `SRC_PATH`. 43 44 Assuming a path separator of `/`, a first argument of `SRC_PATH` and second 45 argument of `DEST_PATH`, the behavior is as follows: 46 47 - `SRC_PATH` specifies a file 48 - `DEST_PATH` does not exist 49 - the file is saved to a file created at `DEST_PATH` 50 - `DEST_PATH` does not exist and ends with `/` 51 - Error condition: the destination directory must exist. 52 - `DEST_PATH` exists and is a file 53 - the destination is overwritten with the source file's contents 54 - `DEST_PATH` exists and is a directory 55 - the file is copied into this directory using the basename from 56 `SRC_PATH` 57 - `SRC_PATH` specifies a directory 58 - `DEST_PATH` does not exist 59 - `DEST_PATH` is created as a directory and the *contents* of the source 60 directory are copied into this directory 61 - `DEST_PATH` exists and is a file 62 - Error condition: cannot copy a directory to a file 63 - `DEST_PATH` exists and is a directory 64 - `SRC_PATH` does not end with `/.` 65 - the source directory is copied into this directory 66 - `SRC_PATH` does end with `/.` 67 - the *content* of the source directory is copied into this 68 directory 69 70 The command requires `SRC_PATH` and `DEST_PATH` to exist according to the above 71 rules. If `SRC_PATH` is local and is a symbolic link, the symbolic link, not 72 the target, is copied by default. To copy the link target and not the link, specify 73 the `-L` option. 74 75 A colon (`:`) is used as a delimiter between `CONTAINER` and its path. You can 76 also use `:` when specifying paths to a `SRC_PATH` or `DEST_PATH` on a local 77 machine, for example `file:name.txt`. If you use a `:` in a local machine path, 78 you must be explicit with a relative or absolute path, for example: 79 80 `/path/to/file:name.txt` or `./file:name.txt` 81 82 It is not possible to copy certain system files such as resources under 83 `/proc`, `/sys`, `/dev`, and mounts created by the user in the container. 84 85 Using `-` as the `SRC_PATH` streams the contents of `STDIN` as a tar archive. 86 The command extracts the content of the tar to the `DEST_PATH` in container's 87 filesystem. In this case, `DEST_PATH` must specify a directory. Using `-` as 88 `DEST_PATH` streams the contents of the resource as a tar archive to `STDOUT`.