github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/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` can 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`.  `docker cp` does *not* create parent directories for
    43  `DEST_PATH` if they do not exist.
    44  
    45  Assuming a path separator of `/`, a first argument of `SRC_PATH` and second
    46  argument of `DEST_PATH`, the behavior is as follows:
    47  
    48  - `SRC_PATH` specifies a file
    49      - `DEST_PATH` does not exist
    50          - the file is saved to a file created at `DEST_PATH`
    51      - `DEST_PATH` does not exist and ends with `/`
    52          - Error condition: the destination directory must exist.
    53      - `DEST_PATH` exists and is a file
    54          - the destination is overwritten with the source file's contents
    55      - `DEST_PATH` exists and is a directory
    56          - the file is copied into this directory using the basename from
    57            `SRC_PATH`
    58  - `SRC_PATH` specifies a directory
    59      - `DEST_PATH` does not exist
    60          - `DEST_PATH` is created as a directory and the *contents* of the source
    61             directory are copied into this directory
    62      - `DEST_PATH` exists and is a file
    63          - Error condition: cannot copy a directory to a file
    64      - `DEST_PATH` exists and is a directory
    65          - `SRC_PATH` does not end with `/.`
    66              - the source directory is copied into this directory
    67          - `SRC_PATH` does end with `/.`
    68              - the *content* of the source directory is copied into this
    69                directory
    70  
    71  The command requires `SRC_PATH` and `DEST_PATH` to exist according to the above
    72  rules. If `SRC_PATH` is local and is a symbolic link, the symbolic link, not
    73  the target, is copied by default. To copy the link target and not the link, specify 
    74  the `-L` option.
    75  
    76  A colon (`:`) is used as a delimiter between `CONTAINER` and its path. You can
    77  also use `:` when specifying paths to a `SRC_PATH` or `DEST_PATH` on a local
    78  machine, for example  `file:name.txt`. If you use a `:` in a local machine path,
    79  you must be explicit with a relative or absolute path, for example:
    80  
    81      `/path/to/file:name.txt` or `./file:name.txt`
    82  
    83  It is not possible to copy certain system files such as resources under
    84  `/proc`, `/sys`, `/dev`, and mounts created by the user in the container.
    85  
    86  Using `-` as the `SRC_PATH` streams the contents of `STDIN` as a tar archive.
    87  The command extracts the content of the tar to the `DEST_PATH` in container's
    88  filesystem. In this case, `DEST_PATH` must specify a directory. Using `-` as
    89  the `DEST_PATH` streams the contents of the resource as a tar archive to `STDOUT`.