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