docs/_data/engine-cli/docker_container_cp.yaml

101 lines
7.9 KiB
YAML

command: docker container cp
short: Copy files/folders between a container and the local filesystem
long: "The `docker container cp` utility copies the contents of `SRC_PATH` to the
`DEST_PATH`.\nYou can copy from the container's file system to the local machine
or the\nreverse, from the local filesystem to the container. If `-` is specified
for\neither the `SRC_PATH` or `DEST_PATH`, you can also stream a tar archive from\n`STDIN`
or to `STDOUT`. The `CONTAINER` can be a running or stopped container.\nThe `SRC_PATH`
or `DEST_PATH` can be a file or directory.\n\nThe `docker container cp` command
assumes container paths are relative to the container's \n`/` (root) directory.
This means supplying the initial forward slash is optional; \nThe command sees `compassionate_darwin:/tmp/foo/myfile.txt`
and\n`compassionate_darwin:tmp/foo/myfile.txt` as identical. Local machine paths
can\nbe an absolute or relative value. The command interprets a local machine's\nrelative
paths as relative to the current working directory where `docker container cp` is\nrun.\n\nThe
`cp` command behaves like the Unix `cp -a` command in that directories are\ncopied
recursively with permissions preserved if possible. Ownership is set to\nthe user
and primary group at the destination. For example, files copied to a\ncontainer
are created with `UID:GID` of the root user. Files copied to the local\nmachine
are created with the `UID:GID` of the user which invoked the `docker container cp`\ncommand.
\ If you specify the `-L` option, `docker container cp` follows any symbolic link\nin
the `SRC_PATH`. `docker container cp` does *not* create parent directories for\n`DEST_PATH`
if they do not exist.\n\nAssuming a path separator of `/`, a first argument of `SRC_PATH`
and second\nargument of `DEST_PATH`, the behavior is as follows:\n\n- `SRC_PATH`
specifies a file\n - `DEST_PATH` does not exist\n - the file is saved
to a file created at `DEST_PATH`\n - `DEST_PATH` does not exist and ends with
`/`\n - Error condition: the destination directory must exist.\n - `DEST_PATH`
exists and is a file\n - the destination is overwritten with the source file's
contents\n - `DEST_PATH` exists and is a directory\n - the file is copied
into this directory using the basename from\n `SRC_PATH`\n- `SRC_PATH`
specifies a directory\n - `DEST_PATH` does not exist\n - `DEST_PATH` is
created as a directory and the *contents* of the source\n directory are
copied into this directory\n - `DEST_PATH` exists and is a file\n - Error
condition: cannot copy a directory to a file\n - `DEST_PATH` exists and is a
directory\n - `SRC_PATH` does not end with `/.` (that is: _slash_ followed
by _dot_)\n - the source directory is copied into this directory\n -
`SRC_PATH` does end with `/.` (that is: _slash_ followed by _dot_)\n -
the *content* of the source directory is copied into this\n directory\n\nThe
command requires `SRC_PATH` and `DEST_PATH` to exist according to the above\nrules.
If `SRC_PATH` is local and is a symbolic link, the symbolic link, not\nthe target,
is copied by default. To copy the link target and not the link, \nspecify the `-L`
option.\n\nA colon (`:`) is used as a delimiter between `CONTAINER` and its path.
You can\nalso use `:` when specifying paths to a `SRC_PATH` or `DEST_PATH` on a
local\nmachine, for example `file:name.txt`. If you use a `:` in a local machine
path,\nyou must be explicit with a relative or absolute path, for example:\n\n `/path/to/file:name.txt`
or `./file:name.txt`\n\nIt is not possible to copy certain system files such as
resources under\n`/proc`, `/sys`, `/dev`, tmpfs, and mounts created by the user
in the container.\nHowever, you can still copy such files by manually running `tar`
in `docker exec`.\nFor example (consider `SRC_PATH` and `DEST_PATH` are directories):\n\n
\ $ docker exec foo tar Ccf $(dirname SRC_PATH) - $(basename SRC_PATH) | tar Cxf
DEST_PATH -\n\nor\n\n $ tar Ccf $(dirname SRC_PATH) - $(basename SRC_PATH) |
docker exec -i foo tar Cxf DEST_PATH -\n\n\nUsing `-` as the `SRC_PATH` streams
the contents of `STDIN` as a tar archive.\nThe command extracts the content of the
tar to the `DEST_PATH` in container's\nfilesystem. In this case, `DEST_PATH` must
specify a directory. Using `-` as\nthe `DEST_PATH` streams the contents of the resource
as a tar archive to `STDOUT`.\n\n# EXAMPLES\n\nSuppose a container has finished
producing some output as a file it saves\nto somewhere in its filesystem. This could
be the output of a build job or\nsome other computation. You can copy these outputs
from the container to a\nlocation on your local host.\n\nIf you want to copy the
`/tmp/foo` directory from a container to the\nexisting `/tmp` directory on your
host. If you run `docker container cp` in your `~`\n(home) directory on the local
host:\n\n $ docker container cp compassionate_darwin:tmp/foo /tmp\n\nDocker creates
a `/tmp/foo` directory on your host. Alternatively, you can omit\nthe leading slash
in the command. If you execute this command from your home\ndirectory:\n\n $
docker container cp compassionate_darwin:tmp/foo tmp\n\nIf `~/tmp` does not exist,
Docker will create it and copy the contents of\n`/tmp/foo` from the container into
this new directory. If `~/tmp` already\nexists as a directory, then Docker will
copy the contents of `/tmp/foo` from\nthe container into a directory at `~/tmp/foo`.\n\nWhen
copying a single file to an existing `LOCALPATH`, the `docker container cp` command\nwill
either overwrite the contents of `LOCALPATH` if it is a file or place it\ninto `LOCALPATH`
if it is a directory, overwriting an existing file of the same\nname if one exists.
For example, this command:\n\n $ docker container cp sharp_ptolemy:/tmp/foo/myfile.txt
/test\n\nIf `/test` does not exist on the local machine, it will be created as a
file\nwith the contents of `/tmp/foo/myfile.txt` from the container. If `/test`\nexists
as a file, it will be overwritten. Lastly, if `/test` exists as a\ndirectory, the
file will be copied to `/test/myfile.txt`.\n\nNext, suppose you want to copy a file
or folder into a container. For example,\nthis could be a configuration file or
some other input to a long running\ncomputation that you would like to place into
a created container before it\nstarts. This is useful because it does not require
the configuration file or\nother input to exist in the container image.\n\nIf you
have a file, `config.yml`, in the current directory on your local host\nand wish
to copy it to an existing directory at `/etc/my-app.d` in a container,\nthis command
can be used:\n\n $ docker container cp config.yml myappcontainer:/etc/my-app.d\n\nIf
you have several files in a local directory `/config` which you need to copy\nto
a directory `/etc/my-app.d` in a container:\n\n $ docker container cp /config/.
myappcontainer:/etc/my-app.d\n\nThe above command will copy the contents of the
local `/config` directory into\nthe directory `/etc/my-app.d` in the container.\n\nFinally,
if you want to copy a symbolic link into a container, you typically\nwant to copy
the linked target and not the link itself. To copy the target, use\nthe `-L` option,
for example:\n\n $ ln -s /tmp/somefile /tmp/somefile.ln\n $ docker container
cp -L /tmp/somefile.ln myappcontainer:/tmp/\n\nThis command copies content of the
local `/tmp/somefile` into the file\n`/tmp/somefile.ln` in the container. Without
`-L` option, the `/tmp/somefile.ln`\npreserves its symbolic link but not its content.\n"
usage: "docker container cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-\n\tdocker cp
[OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH"
pname: docker container
plink: docker_container.yaml
options:
- option: follow-link
shorthand: L
default_value: "false"
description: Always follow symbol link in SRC_PATH