2014-04-16 14:07:55 -04:00
|
|
|
% DOCKER(1) Docker User Manuals
|
2014-06-30 22:58:04 -04:00
|
|
|
% Docker Community
|
|
|
|
% JUNE 2014
|
2014-04-16 14:07:55 -04:00
|
|
|
# NAME
|
2015-05-15 14:35:41 -04:00
|
|
|
docker-cp - Copy files/folders between a container and the local filesystem.
|
2014-04-16 14:07:55 -04:00
|
|
|
|
|
|
|
# SYNOPSIS
|
2014-06-30 22:58:04 -04:00
|
|
|
**docker cp**
|
2014-10-15 17:14:12 -04:00
|
|
|
[**--help**]
|
2015-10-01 03:56:39 -04:00
|
|
|
CONTAINER:SRC_PATH DEST_PATH|-
|
2015-11-09 20:33:55 -05:00
|
|
|
|
|
|
|
**docker cp**
|
|
|
|
[**--help**]
|
2015-10-01 03:56:39 -04:00
|
|
|
SRC_PATH|- CONTAINER:DEST_PATH
|
2014-04-16 14:07:55 -04:00
|
|
|
|
|
|
|
# DESCRIPTION
|
2015-03-10 21:40:20 -04:00
|
|
|
|
2015-10-01 03:56:39 -04:00
|
|
|
The `docker cp` utility copies the contents of `SRC_PATH` to the `DEST_PATH`.
|
|
|
|
You can copy from the container's file system to the local machine or the
|
|
|
|
reverse, from the local filesystem to the container. If `-` is specified for
|
|
|
|
either the `SRC_PATH` or `DEST_PATH`, you can also stream a tar archive from
|
|
|
|
`STDIN` or to `STDOUT`. The `CONTAINER` can be a running or stopped container.
|
2016-02-24 20:48:21 -05:00
|
|
|
The `SRC_PATH` or `DEST_PATH` can be a file or directory.
|
2015-10-01 03:56:39 -04:00
|
|
|
|
|
|
|
The `docker cp` command assumes container paths are relative to the container's
|
|
|
|
`/` (root) directory. This means supplying the initial forward slash is optional;
|
|
|
|
The command sees `compassionate_darwin:/tmp/foo/myfile.txt` and
|
|
|
|
`compassionate_darwin:tmp/foo/myfile.txt` as identical. Local machine paths can
|
|
|
|
be an absolute or relative value. The command interprets a local machine's
|
|
|
|
relative paths as relative to the current working directory where `docker cp` is
|
|
|
|
run.
|
|
|
|
|
|
|
|
The `cp` command behaves like the Unix `cp -a` command in that directories are
|
2015-05-15 14:35:41 -04:00
|
|
|
copied recursively with permissions preserved if possible. Ownership is set to
|
2015-10-01 03:56:39 -04:00
|
|
|
the user and primary group at the destination. For example, files copied to a
|
|
|
|
container are created with `UID:GID` of the root user. Files copied to the local
|
|
|
|
machine are created with the `UID:GID` of the user which invoked the `docker cp`
|
|
|
|
command. If you specify the `-L` option, `docker cp` follows any symbolic link
|
2016-03-03 18:40:28 -05:00
|
|
|
in the `SRC_PATH`. `docker cp` does *not* create parent directories for
|
|
|
|
`DEST_PATH` if they do not exist.
|
2015-05-15 14:35:41 -04:00
|
|
|
|
|
|
|
Assuming a path separator of `/`, a first argument of `SRC_PATH` and second
|
2015-10-01 03:56:39 -04:00
|
|
|
argument of `DEST_PATH`, the behavior is as follows:
|
2015-05-15 14:35:41 -04:00
|
|
|
|
|
|
|
- `SRC_PATH` specifies a file
|
2015-10-01 03:56:39 -04:00
|
|
|
- `DEST_PATH` does not exist
|
|
|
|
- the file is saved to a file created at `DEST_PATH`
|
|
|
|
- `DEST_PATH` does not exist and ends with `/`
|
2015-05-15 14:35:41 -04:00
|
|
|
- Error condition: the destination directory must exist.
|
2015-10-01 03:56:39 -04:00
|
|
|
- `DEST_PATH` exists and is a file
|
|
|
|
- the destination is overwritten with the source file's contents
|
|
|
|
- `DEST_PATH` exists and is a directory
|
2015-05-15 14:35:41 -04:00
|
|
|
- the file is copied into this directory using the basename from
|
|
|
|
`SRC_PATH`
|
|
|
|
- `SRC_PATH` specifies a directory
|
2015-10-01 03:56:39 -04:00
|
|
|
- `DEST_PATH` does not exist
|
|
|
|
- `DEST_PATH` is created as a directory and the *contents* of the source
|
2015-05-15 14:35:41 -04:00
|
|
|
directory are copied into this directory
|
2015-10-01 03:56:39 -04:00
|
|
|
- `DEST_PATH` exists and is a file
|
2015-05-15 14:35:41 -04:00
|
|
|
- Error condition: cannot copy a directory to a file
|
2015-10-01 03:56:39 -04:00
|
|
|
- `DEST_PATH` exists and is a directory
|
2015-05-15 14:35:41 -04:00
|
|
|
- `SRC_PATH` does not end with `/.`
|
|
|
|
- the source directory is copied into this directory
|
2015-09-14 21:47:16 -04:00
|
|
|
- `SRC_PATH` does end with `/.`
|
2015-05-15 14:35:41 -04:00
|
|
|
- the *content* of the source directory is copied into this
|
|
|
|
directory
|
|
|
|
|
2015-10-01 03:56:39 -04:00
|
|
|
The command requires `SRC_PATH` and `DEST_PATH` to exist according to the above
|
2015-05-15 14:35:41 -04:00
|
|
|
rules. If `SRC_PATH` is local and is a symbolic link, the symbolic link, not
|
2015-10-01 03:56:39 -04:00
|
|
|
the target, is copied by default. To copy the link target and not the link,
|
|
|
|
specify the `-L` option.
|
2015-05-15 14:35:41 -04:00
|
|
|
|
2015-10-01 03:56:39 -04:00
|
|
|
A colon (`:`) is used as a delimiter between `CONTAINER` and its path. You can
|
|
|
|
also use `:` when specifying paths to a `SRC_PATH` or `DEST_PATH` on a local
|
|
|
|
machine, for example `file:name.txt`. If you use a `:` in a local machine path,
|
|
|
|
you must be explicit with a relative or absolute path, for example:
|
2015-05-15 14:35:41 -04:00
|
|
|
|
|
|
|
`/path/to/file:name.txt` or `./file:name.txt`
|
|
|
|
|
|
|
|
It is not possible to copy certain system files such as resources under
|
2016-05-23 05:10:14 -04:00
|
|
|
`/proc`, `/sys`, `/dev`, tmpfs, and mounts created by the user in the container.
|
|
|
|
However, you can still copy such files by manually running `tar` in `docker exec`.
|
|
|
|
For example (consider `SRC_PATH` and `DEST_PATH` are directories):
|
|
|
|
|
|
|
|
$ docker exec foo tar Ccf $(dirname SRC_PATH) - $(basename SRC_PATH) | tar Cxf DEST_PATH -
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
$ tar Ccf $(dirname SRC_PATH) - $(basename SRC_PATH) | docker exec -i foo tar Cxf DEST_PATH -
|
|
|
|
|
2015-05-15 14:35:41 -04:00
|
|
|
|
2015-10-01 03:56:39 -04:00
|
|
|
Using `-` as the `SRC_PATH` streams the contents of `STDIN` as a tar archive.
|
|
|
|
The command extracts the content of the tar to the `DEST_PATH` in container's
|
|
|
|
filesystem. In this case, `DEST_PATH` must specify a directory. Using `-` as
|
2016-02-24 20:48:21 -05:00
|
|
|
the `DEST_PATH` streams the contents of the resource as a tar archive to `STDOUT`.
|
2015-05-15 14:35:41 -04:00
|
|
|
|
|
|
|
# OPTIONS
|
2015-10-01 03:56:39 -04:00
|
|
|
**-L**, **--follow-link**=*true*|*false*
|
|
|
|
Follow symbol link in SRC_PATH
|
|
|
|
|
2015-05-15 14:35:41 -04:00
|
|
|
**--help**
|
|
|
|
Print usage statement
|
|
|
|
|
|
|
|
# EXAMPLES
|
|
|
|
|
|
|
|
Suppose a container has finished producing some output as a file it saves
|
|
|
|
to somewhere in its filesystem. This could be the output of a build job or
|
|
|
|
some other computation. You can copy these outputs from the container to a
|
|
|
|
location on your local host.
|
2015-03-10 21:40:20 -04:00
|
|
|
|
2015-05-15 14:35:41 -04:00
|
|
|
If you want to copy the `/tmp/foo` directory from a container to the
|
|
|
|
existing `/tmp` directory on your host. If you run `docker cp` in your `~`
|
|
|
|
(home) directory on the local host:
|
2015-03-10 21:40:20 -04:00
|
|
|
|
2015-10-01 03:56:39 -04:00
|
|
|
$ docker cp compassionate_darwin:tmp/foo /tmp
|
2015-03-10 21:40:20 -04:00
|
|
|
|
|
|
|
Docker creates a `/tmp/foo` directory on your host. Alternatively, you can omit
|
2015-05-15 14:35:41 -04:00
|
|
|
the leading slash in the command. If you execute this command from your home
|
|
|
|
directory:
|
2015-03-10 21:40:20 -04:00
|
|
|
|
2015-10-01 03:56:39 -04:00
|
|
|
$ docker cp compassionate_darwin:tmp/foo tmp
|
2015-03-10 21:40:20 -04:00
|
|
|
|
2015-05-15 14:35:41 -04:00
|
|
|
If `~/tmp` does not exist, Docker will create it and copy the contents of
|
|
|
|
`/tmp/foo` from the container into this new directory. If `~/tmp` already
|
|
|
|
exists as a directory, then Docker will copy the contents of `/tmp/foo` from
|
|
|
|
the container into a directory at `~/tmp/foo`.
|
2015-03-10 21:40:20 -04:00
|
|
|
|
2015-05-15 14:35:41 -04:00
|
|
|
When copying a single file to an existing `LOCALPATH`, the `docker cp` command
|
|
|
|
will either overwrite the contents of `LOCALPATH` if it is a file or place it
|
|
|
|
into `LOCALPATH` if it is a directory, overwriting an existing file of the same
|
|
|
|
name if one exists. For example, this command:
|
2015-03-10 21:40:20 -04:00
|
|
|
|
2015-10-01 03:56:39 -04:00
|
|
|
$ docker cp sharp_ptolemy:/tmp/foo/myfile.txt /test
|
2015-03-10 21:40:20 -04:00
|
|
|
|
2015-05-15 14:35:41 -04:00
|
|
|
If `/test` does not exist on the local machine, it will be created as a file
|
|
|
|
with the contents of `/tmp/foo/myfile.txt` from the container. If `/test`
|
2015-11-05 01:17:37 -05:00
|
|
|
exists as a file, it will be overwritten. Lastly, if `/test` exists as a
|
2015-05-15 14:35:41 -04:00
|
|
|
directory, the file will be copied to `/test/myfile.txt`.
|
2015-03-10 21:40:20 -04:00
|
|
|
|
2015-05-15 14:35:41 -04:00
|
|
|
Next, suppose you want to copy a file or folder into a container. For example,
|
|
|
|
this could be a configuration file or some other input to a long running
|
|
|
|
computation that you would like to place into a created container before it
|
|
|
|
starts. This is useful because it does not require the configuration file or
|
|
|
|
other input to exist in the container image.
|
2015-03-10 21:40:20 -04:00
|
|
|
|
2015-05-15 14:35:41 -04:00
|
|
|
If you have a file, `config.yml`, in the current directory on your local host
|
|
|
|
and wish to copy it to an existing directory at `/etc/my-app.d` in a container,
|
|
|
|
this command can be used:
|
2015-03-10 21:40:20 -04:00
|
|
|
|
2015-10-01 03:56:39 -04:00
|
|
|
$ docker cp config.yml myappcontainer:/etc/my-app.d
|
2014-04-16 14:07:55 -04:00
|
|
|
|
2015-05-15 14:35:41 -04:00
|
|
|
If you have several files in a local directory `/config` which you need to copy
|
|
|
|
to a directory `/etc/my-app.d` in a container:
|
2014-06-30 22:58:04 -04:00
|
|
|
|
2015-10-01 03:56:39 -04:00
|
|
|
$ docker cp /config/. myappcontainer:/etc/my-app.d
|
2014-04-16 14:07:55 -04:00
|
|
|
|
2015-05-15 14:35:41 -04:00
|
|
|
The above command will copy the contents of the local `/config` directory into
|
|
|
|
the directory `/etc/my-app.d` in the container.
|
2014-04-16 14:07:55 -04:00
|
|
|
|
2015-10-01 03:56:39 -04:00
|
|
|
Finally, if you want to copy a symbolic link into a container, you typically
|
|
|
|
want to copy the linked target and not the link itself. To copy the target, use
|
|
|
|
the `-L` option, for example:
|
|
|
|
|
|
|
|
$ ln -s /tmp/somefile /tmp/somefile.ln
|
|
|
|
$ docker cp -L /tmp/somefile.ln myappcontainer:/tmp/
|
|
|
|
|
|
|
|
This command copies content of the local `/tmp/somefile` into the file
|
|
|
|
`/tmp/somefile.ln` in the container. Without `-L` option, the `/tmp/somefile.ln`
|
|
|
|
preserves its symbolic link but not its content.
|
|
|
|
|
2014-04-16 14:07:55 -04:00
|
|
|
# HISTORY
|
|
|
|
April 2014, Originally compiled by William Henry (whenry at redhat dot com)
|
2014-07-01 20:30:25 -04:00
|
|
|
based on docker.com source material and internal work.
|
2014-06-30 22:58:04 -04:00
|
|
|
June 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>
|
2015-05-15 14:35:41 -04:00
|
|
|
May 2015, updated by Josh Hawn <josh.hawn@docker.com>
|