Browse code

Clarify behavior of docker cp

The STDOUT behavior of cp is not yet released in 1.50 so removed.
Also, tested against 1.5 all other behaviors and extended documentation to match.
Renamed HOSTPATH to HOSTDIR to give a self documenting name.

Adding back in the references to STDOUT
fix the command string
Entering Doug's comment re append and ~/tmp/foo in the glass
Adding in Doug's comments regarding PATHs and missing |-
Updating with James comments

Signed-off-by: Mary Anthony <mary@docker.com>

Mary Anthony authored on 2015/03/11 10:40:20
Showing 3 changed files
... ...
@@ -2458,7 +2458,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
2458 2458
 }
2459 2459
 
2460 2460
 func (cli *DockerCli) CmdCp(args ...string) error {
2461
-	cmd := cli.Subcmd("cp", "CONTAINER:PATH HOSTPATH|-", "Copy files/folders from the PATH to the HOSTPATH. Use '-' to write the data\nas a tar file to STDOUT.", true)
2461
+	cmd := cli.Subcmd("cp", "CONTAINER:PATH HOSTDIR|-", "Copy files/folders from a PATH on the container to a HOSTDIR on the host\nrunning the command. Use '-' to write the data\nas a tar file to STDOUT.", true)
2462 2462
 	cmd.Require(flag.Exact, 2)
2463 2463
 
2464 2464
 	utils.ParseFlags(cmd, args, true)
... ...
@@ -2,18 +2,57 @@
2 2
 % Docker Community
3 3
 % JUNE 2014
4 4
 # NAME
5
-docker-cp - Copy files/folders from the PATH to the HOSTPATH, or STDOUT
5
+docker-cp - Copy files or folders from a container's PATH to a HOSTDIR
6
+or to STDOUT.
6 7
 
7 8
 # SYNOPSIS
8 9
 **docker cp**
9 10
 [**--help**]
10
-CONTAINER:PATH HOSTPATH|-
11
+CONTAINER:PATH HOSTDIR|-
11 12
 
12 13
 # DESCRIPTION
13
-Copy files/folders from a container's filesystem to the
14
-path. Use '-' to write the data as a tar file to STDOUT.
15
-Paths are relative to the root of the filesystem. Files
16
-can be copied from a running or stopped container.
14
+
15
+Copy files or folders from a `CONTAINER:PATH` to the `HOSTDIR` or to `STDOUT`. 
16
+The `CONTAINER:PATH` is relative to the root of the container's filesystem. You
17
+can copy from either a running or stopped container. 
18
+
19
+The `PATH` can be a file or directory. The `docker cp` command assumes all
20
+`PATH` values start at the `/` (root) directory. This means supplying the
21
+initial forward slash is optional; The command sees
22
+`compassionate_darwin:/tmp/foo/myfile.txt` and
23
+`compassionate_darwin:tmp/foo/myfile.txt` as identical.
24
+
25
+The `HOSTDIR` refers to a directory on the host. If you do not specify an
26
+absolute path for your `HOSTDIR` value, Docker creates the directory relative to
27
+where you run the `docker cp` command. For example, suppose you want to copy the
28
+`/tmp/foo` directory from a container to the `/tmp` directory on your host. If
29
+you run `docker cp` in your `~` (home) directory on the host:
30
+
31
+		$ docker cp compassionate_darwin:tmp/foo /tmp
32
+
33
+Docker creates a `/tmp/foo` directory on your host. Alternatively, you can omit
34
+the leading slash in the command. If you execute this command from your home directory:
35
+
36
+		$ docker cp compassionate_darwin:tmp/foo tmp
37
+
38
+Docker creates a `~/tmp/foo` subdirectory.  
39
+
40
+When copying files to an existing `HOSTDIR`, the `cp` command adds the new files to
41
+the directory. For example, this command:
42
+
43
+		$ docker cp sharp_ptolemy:/tmp/foo/myfile.txt /tmp
44
+
45
+Creates a `/tmp/foo` directory on the host containing the `myfile.txt` file. If
46
+you repeat the command but change the filename:
47
+
48
+		$ docker cp sharp_ptolemy:/tmp/foo/secondfile.txt /tmp
49
+
50
+Your host's `/tmp/foo` directory will contain both files:
51
+
52
+		$ ls /tmp/foo
53
+		myfile.txt secondfile.txt
54
+		
55
+Finally, use '-' to write the data as a `tar` file to STDOUT.
17 56
 
18 57
 # OPTIONS
19 58
 **--help**
... ...
@@ -756,14 +756,13 @@ Supported `Dockerfile` instructions: `CMD`, `ENTRYPOINT`, `ENV`, `EXPOSE`,
756 756
 
757 757
 ## cp
758 758
 
759
-Copy files/folders from a container's filesystem to the
760
-path.  Use '-' to write the data as a tar file to STDOUT.
761
-Paths are relative to the root of the filesystem.
759
+Copy files or folders from a container's filesystem to the directory on the
760
+host.  Use '-' to write the data as a tar file to `STDOUT`. `CONTAINER:PATH` is
761
+relative to the root of the container's filesystem.
762 762
 
763
-    Usage: docker cp CONTAINER:PATH HOSTPATH|-
763
+    Usage: docker cp CONTAINER:PATH HOSTDIR|-
764 764
 
765
-    Copy files/folders from the PATH to the HOSTPATH. Use '-' to write the data
766
-	as a tar file to STDOUT.
765
+    Copy files/folders from the PATH to the HOSTDIR. 
767 766
 
768 767
 
769 768
 ## create