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