github.com/uppal0016/docker_new@v0.0.0-20240123060250-1c98be13ac2c/man/docker-cp.1.md (about) 1 % DOCKER(1) Docker User Manuals 2 % Docker Community 3 % JUNE 2014 4 # NAME 5 docker-cp - Copy files/folders between a container and the local filesystem. 6 7 # SYNOPSIS 8 **docker cp** 9 [**--help**] 10 CONTAINER:SRC_PATH DEST_PATH|- 11 12 **docker cp** 13 [**--help**] 14 SRC_PATH|- CONTAINER:DEST_PATH 15 16 # DESCRIPTION 17 18 The `docker cp` utility copies the contents of `SRC_PATH` to the `DEST_PATH`. 19 You can copy from the container's file system to the local machine or the 20 reverse, from the local filesystem to the container. If `-` is specified for 21 either the `SRC_PATH` or `DEST_PATH`, you can also stream a tar archive from 22 `STDIN` or to `STDOUT`. The `CONTAINER` can be a running or stopped container. 23 The `SRC_PATH` or `DEST_PATH` can be a file or directory. 24 25 The `docker cp` command assumes container paths are relative to the container's 26 `/` (root) directory. This means supplying the initial forward slash is optional; 27 The command sees `compassionate_darwin:/tmp/foo/myfile.txt` and 28 `compassionate_darwin:tmp/foo/myfile.txt` as identical. Local machine paths can 29 be an absolute or relative value. The command interprets a local machine's 30 relative paths as relative to the current working directory where `docker cp` is 31 run. 32 33 The `cp` command behaves like the Unix `cp -a` command in that directories are 34 copied recursively with permissions preserved if possible. Ownership is set to 35 the user and primary group at the destination. For example, files copied to a 36 container are created with `UID:GID` of the root user. Files copied to the local 37 machine are created with the `UID:GID` of the user which invoked the `docker cp` 38 command. If you specify the `-L` option, `docker cp` follows any symbolic link 39 in the `SRC_PATH`. `docker cp` does *not* create parent directories for 40 `DEST_PATH` if they do not exist. 41 42 Assuming a path separator of `/`, a first argument of `SRC_PATH` and second 43 argument of `DEST_PATH`, the behavior is as follows: 44 45 - `SRC_PATH` specifies a file 46 - `DEST_PATH` does not exist 47 - the file is saved to a file created at `DEST_PATH` 48 - `DEST_PATH` does not exist and ends with `/` 49 - Error condition: the destination directory must exist. 50 - `DEST_PATH` exists and is a file 51 - the destination is overwritten with the source file's contents 52 - `DEST_PATH` exists and is a directory 53 - the file is copied into this directory using the basename from 54 `SRC_PATH` 55 - `SRC_PATH` specifies a directory 56 - `DEST_PATH` does not exist 57 - `DEST_PATH` is created as a directory and the *contents* of the source 58 directory are copied into this directory 59 - `DEST_PATH` exists and is a file 60 - Error condition: cannot copy a directory to a file 61 - `DEST_PATH` exists and is a directory 62 - `SRC_PATH` does not end with `/.` 63 - the source directory is copied into this directory 64 - `SRC_PATH` does end with `/.` 65 - the *content* of the source directory is copied into this 66 directory 67 68 The command requires `SRC_PATH` and `DEST_PATH` to exist according to the above 69 rules. If `SRC_PATH` is local and is a symbolic link, the symbolic link, not 70 the target, is copied by default. To copy the link target and not the link, 71 specify the `-L` option. 72 73 A colon (`:`) is used as a delimiter between `CONTAINER` and its path. You can 74 also use `:` when specifying paths to a `SRC_PATH` or `DEST_PATH` on a local 75 machine, for example `file:name.txt`. If you use a `:` in a local machine path, 76 you must be explicit with a 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 `SRC_PATH` streams the contents of `STDIN` as a tar archive. 84 The command extracts the content of the tar to the `DEST_PATH` in container's 85 filesystem. In this case, `DEST_PATH` must specify a directory. Using `-` as 86 the `DEST_PATH` streams the contents of the resource as a tar archive to `STDOUT`. 87 88 # OPTIONS 89 **-L**, **--follow-link**=*true*|*false* 90 Follow symbol link in SRC_PATH 91 92 **--help** 93 Print usage statement 94 95 # EXAMPLES 96 97 Suppose a container has finished producing some output as a file it saves 98 to somewhere in its filesystem. This could be the output of a build job or 99 some other computation. You can copy these outputs from the container to a 100 location on your local host. 101 102 If you want to copy the `/tmp/foo` directory from a container to the 103 existing `/tmp` directory on your host. If you run `docker cp` in your `~` 104 (home) directory on the local host: 105 106 $ docker cp compassionate_darwin:tmp/foo /tmp 107 108 Docker creates a `/tmp/foo` directory on your host. Alternatively, you can omit 109 the leading slash in the command. If you execute this command from your home 110 directory: 111 112 $ docker cp compassionate_darwin:tmp/foo tmp 113 114 If `~/tmp` does not exist, Docker will create it and copy the contents of 115 `/tmp/foo` from the container into this new directory. If `~/tmp` already 116 exists as a directory, then Docker will copy the contents of `/tmp/foo` from 117 the container into a directory at `~/tmp/foo`. 118 119 When copying a single file to an existing `LOCALPATH`, the `docker cp` command 120 will either overwrite the contents of `LOCALPATH` if it is a file or place it 121 into `LOCALPATH` if it is a directory, overwriting an existing file of the same 122 name if one exists. For example, this command: 123 124 $ docker cp sharp_ptolemy:/tmp/foo/myfile.txt /test 125 126 If `/test` does not exist on the local machine, it will be created as a file 127 with the contents of `/tmp/foo/myfile.txt` from the container. If `/test` 128 exists as a file, it will be overwritten. Lastly, if `/test` exists as a 129 directory, the file will be copied to `/test/myfile.txt`. 130 131 Next, suppose you want to copy a file or folder into a container. For example, 132 this could be a configuration file or some other input to a long running 133 computation that you would like to place into a created container before it 134 starts. This is useful because it does not require the configuration file or 135 other input to exist in the container image. 136 137 If you have a file, `config.yml`, in the current directory on your local host 138 and wish to copy it to an existing directory at `/etc/my-app.d` in a container, 139 this command can be used: 140 141 $ docker cp config.yml myappcontainer:/etc/my-app.d 142 143 If you have several files in a local directory `/config` which you need to copy 144 to a directory `/etc/my-app.d` in a container: 145 146 $ docker cp /config/. myappcontainer:/etc/my-app.d 147 148 The above command will copy the contents of the local `/config` directory into 149 the directory `/etc/my-app.d` in the container. 150 151 Finally, if you want to copy a symbolic link into a container, you typically 152 want to copy the linked target and not the link itself. To copy the target, use 153 the `-L` option, for example: 154 155 $ ln -s /tmp/somefile /tmp/somefile.ln 156 $ docker cp -L /tmp/somefile.ln myappcontainer:/tmp/ 157 158 This command copies content of the local `/tmp/somefile` into the file 159 `/tmp/somefile.ln` in the container. Without `-L` option, the `/tmp/somefile.ln` 160 preserves its symbolic link but not its content. 161 162 # HISTORY 163 April 2014, Originally compiled by William Henry (whenry at redhat dot com) 164 based on docker.com source material and internal work. 165 June 2014, updated by Sven Dowideit <SvenDowideit@home.org.au> 166 May 2015, updated by Josh Hawn <josh.hawn@docker.com>