{"action":"created","comment":{"url":"https://api.github.com/repos/docker/docker/pulls/comments/34937615","id":34937615,"diff_hunk":"@@ -10,48 +16,286 @@ import (\n \tflag \"github.com/docker/docker/pkg/mflag\"\n )\n \n-// CmdCp copies files/folders from a path on the container to a directory on the host running the command.\n+type copyDirection int\n+\n+const (\n+\tfromContainer copyDirection = (1 << iota)\n+\ttoContainer\n+\tacrossContainers = fromContainer | toContainer\n+)\n+\n+// CmdCp copies files/folders to or from a path in a container.\n //\n-// If HOSTDIR is '-', the data is written as a tar file to STDOUT.\n+// When copying from a container, if LOCALPATH is '-' the data is written as a\n+// tar archive file to STDOUT.\n //\n-// Usage: docker cp CONTAINER:PATH HOSTDIR\n+// When copying to a container, if LOCALPATH is '-' the data is read as a tar\n+// archive file from STDIN, and the destination CONTAINER:PATH, must specify\n+// a directory.\n+//\n+// Usage:\n+// \tdocker cp CONTAINER:PATH LOCALPATH|-\n+// \tdocker cp LOCALPATH|- CONTAINER:PATH\n func (cli *DockerCli) CmdCp(args ...string) error {\n-\tcmd := cli.Subcmd(\"cp\", []string{\"CONTAINER:PATH HOSTDIR|-\"}, \"Copy files/folders from a container's PATH to a HOSTDIR on the host\\nrunning the command. Use '-' to write the data as a tar file to STDOUT.\", true)\n-\tcmd.Require(flag.Exact, 2)\n+\tcmd := cli.Subcmd(\n+\t\t\"cp\",\n+\t\t[]string{\"CONTAINER:PATH LOCALPATH|-\", \"LOCALPATH|- CONTAINER:PATH\"},\n+\t\tstrings.Join([]string{\n+\t\t\t\"Copy files/folders between a container and the local filesystem.\\n\",\n+\t\t\t\"Use '-' as the source argument to extract a tar archive read from stdin\\n\",\n+\t\t\t\"to a directory destination in a container.\\n\",\n+\t\t\t\"Use '-' as the destinationargument to stream a tar archive of the\\n\",","path":"api/client/cp.go","position":52,"original_position":52,"commit_id":"b5e2fb605d88d63d2a7589970af32a5055f99175","original_commit_id":"b5e2fb605d88d63d2a7589970af32a5055f99175","user":{"login":"calavera","id":1050,"avatar_url":"https://avatars.githubusercontent.com/u/1050?v=3","gravatar_id":"","url":"https://api.github.com/users/calavera","html_url":"https://github.com/calavera","followers_url":"https://api.github.com/users/calavera/followers","following_url":"https://api.github.com/users/calavera/following{/other_user}","gists_url":"https://api.github.com/users/calavera/gists{/gist_id}","starred_url":"https://api.github.com/users/calavera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calavera/subscriptions","organizations_url":"https://api.github.com/users/calavera/orgs","repos_url":"https://api.github.com/users/calavera/repos","events_url":"https://api.github.com/users/calavera/events{/privacy}","received_events_url":"https://api.github.com/users/calavera/received_events","type":"User","site_admin":false},"body":"needs a space between `destination` and `argument`. A small re-wording that might be slightly more clear:\r\n\r\n```\r\nCopy files and folders between container and their host.\\n\r\nUse \"-\" as source, to extract a tar archive from stdin to a directory destination inside a container.\\n\r\nUse \"-\" as destination, to stream a tar archive with a container source to stdout.\\n\r\n```","created_at":"2015-07-17T22:48:42Z","updated_at":"2015-07-17T22:48:42Z","html_url":"https://github.com/docker/docker/pull/13171#discussion_r34937615","pull_request_url":"https://api.github.com/repos/docker/docker/pulls/13171","_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/comments/34937615"},"html":{"href":"https://github.com/docker/docker/pull/13171#discussion_r34937615"},"pull_request":{"href":"https://api.github.com/repos/docker/docker/pulls/13171"}}},"pull_request":{"url":"https://api.github.com/repos/docker/docker/pulls/13171","id":35286801,"html_url":"https://github.com/docker/docker/pull/13171","diff_url":"https://github.com/docker/docker/pull/13171.diff","patch_url":"https://github.com/docker/docker/pull/13171.patch","issue_url":"https://api.github.com/repos/docker/docker/issues/13171","number":13171,"state":"open","locked":false,"title":"docker cp to and from containers","user":{"login":"jlhawn","id":1441929,"avatar_url":"https://avatars.githubusercontent.com/u/1441929?v=3","gravatar_id":"","url":"https://api.github.com/users/jlhawn","html_url":"https://github.com/jlhawn","followers_url":"https://api.github.com/users/jlhawn/followers","following_url":"https://api.github.com/users/jlhawn/following{/other_user}","gists_url":"https://api.github.com/users/jlhawn/gists{/gist_id}","starred_url":"https://api.github.com/users/jlhawn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlhawn/subscriptions","organizations_url":"https://api.github.com/users/jlhawn/orgs","repos_url":"https://api.github.com/users/jlhawn/repos","events_url":"https://api.github.com/users/jlhawn/events{/privacy}","received_events_url":"https://api.github.com/users/jlhawn/received_events","type":"User","site_admin":false},"body":"## Copy files/folders between containers and the local filesystem.\r\n\r\n    Usage:  docker cp [options] CONTAINER:PATH LOCALPATH|-\r\n            docker cp [options] LOCALPATH|- CONTAINER:PATH\r\n\r\n    --help  Print usage statement\r\n\r\nIn the first synopsis form, the `docker cp` utility copies the contents of\r\n`PATH` from the filesystem of `CONTAINER` to the `LOCALPATH` (or stream as\r\na Tar Archive to `STDOUT` if `-` is specified).\r\n\r\nIn the second synopsis form, the contents of `LOCALPATH` (or a Tar Archive\r\nstreamed from `STDIN` if `-` is specified) are copied from the local machine to\r\n`PATH` in the filesystem of `CONTAINER`.\r\n\r\nYou can copy to or from either a running or stopped container. The `PATH` can\r\nbe a file or directory. The `docker cp` command assumes all `CONTAINER:PATH`\r\nvalues are relative to the `/` (root) directory of the container. This means\r\nsupplying the initial forward slash is optional; The command sees\r\n`compassionate_darwin:/tmp/foo/myfile.txt` and\r\n`compassionate_darwin:tmp/foo/myfile.txt` as identical. If a `LOCALPATH` value\r\nis not absolute, is it considered relative to the current working directory.\r\n\r\nBehavior is similar to the common Unix utility `cp -a` in that directories are\r\ncopied recursively and file mode, permission, and ownership are preserved if\r\npossible.\r\n\r\nAssuming a path separator of `/`, a first argument of `SRC_PATH` and second\r\nargument of `DST_PATH`, the behavior is as follows:\r\n\r\n- `SRC_PATH` specifies a file\r\n    - `DST_PATH` does not exist\r\n        - the file is saved to a file created at `DST_PATH`\r\n    - `DST_PATH` does not exist and ends with `/`\r\n        - Error condition: the destination directory must exist.\r\n    - `DST_PATH` exists and is a file\r\n        - the destination is overwritten with the contents of the source file\r\n    - `DST_PATH` exists and is a directory\r\n        - the file is copied into this directory using the basename from\r\n          `SRC_PATH`\r\n- `SRC_PATH` specifies a directory\r\n    - `DST_PATH` does not exist\r\n        - `DST_PATH` is created as a directory and the *contents* of the source\r\n           directory are copied into this directory\r\n    - `DST_PATH` exists and is a file\r\n        - Error condition: cannot copy a directory to a file\r\n    - `DST_PATH` exists and is a directory\r\n        - `SRC_PATH` does not end with `/.`\r\n            - the source directory is copied into this directory\r\n        - `SRC_PAPTH` does end with `/.`\r\n            - the *content* of the source directory is copied into this\r\n              directory\r\n\r\nThe command requires `SRC_PATH` and `DST_PATH` to exist according to the above\r\nrules. If `SRC_PATH` is a symbolic link, the symbolic link, not the target, is\r\ncopied. If a path separator immediately follows the symbolic link, it will be\r\nresolved to its target and the target resource will be copied.\r\n\r\nA colon (`:`) is used as a delimiter between `CONTAINER` and `PATH`, but `:`\r\ncould also be in a valid `LOCALPATH`, like `file:name.txt`. This ambiguity is\r\nresolved by requiring a `LOCALPATH` with a `:` to be made explicit with a\r\nrelative or absolute path, for example:\r\n\r\n    `/path/to/file:name.txt` or `./file:name.txt`\r\n\r\nIt is not possible to copy certain system files such as resources under\r\n`/proc`, `/sys`, `/dev`, and mounts created by the user in the container.\r\n\r\nUsing `-` as the first argument in place of a `LOCALPATH` will stream the\r\ncontents of `STDIN` as a Tar Archive which will be extracted to the `PATH` in\r\nthe filesystem of the destination container. In this case, `PATH` must specify\r\na directory.\r\n\r\nUsing `-` as the second argument in place of a `LOCALPATH` will stream the\r\ncontents of the resource from the source container as a Tar Archive to\r\n`STDOUT`.\r\n\r\nreplaces https://github.com/docker/docker/pull/10198\r\n\r\nfixes #5846\r\nfixes #4272\r\nfixes #10040","created_at":"2015-05-13T01:25:08Z","updated_at":"2015-07-17T22:48:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c1e7419cab9bf7c4995e8df77b21228421f507f7","assignee":{"login":"jlhawn","id":1441929,"avatar_url":"https://avatars.githubusercontent.com/u/1441929?v=3","gravatar_id":"","url":"https://api.github.com/users/jlhawn","html_url":"https://github.com/jlhawn","followers_url":"https://api.github.com/users/jlhawn/followers","following_url":"https://api.github.com/users/jlhawn/following{/other_user}","gists_url":"https://api.github.com/users/jlhawn/gists{/gist_id}","starred_url":"https://api.github.com/users/jlhawn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlhawn/subscriptions","organizations_url":"https://api.github.com/users/jlhawn/orgs","repos_url":"https://api.github.com/users/jlhawn/repos","events_url":"https://api.github.com/users/jlhawn/events{/privacy}","received_events_url":"https://api.github.com/users/jlhawn/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/docker/docker/milestones/39","html_url":"https://github.com/docker/docker/milestones/1.8.0","labels_url":"https://api.github.com/repos/docker/docker/milestones/39/labels","id":1151952,"number":39,"title":"1.8.0","description":"","creator":{"login":"thaJeztah","id":1804568,"avatar_url":"https://avatars.githubusercontent.com/u/1804568?v=3","gravatar_id":"","url":"https://api.github.com/users/thaJeztah","html_url":"https://github.com/thaJeztah","followers_url":"https://api.github.com/users/thaJeztah/followers","following_url":"https://api.github.com/users/thaJeztah/following{/other_user}","gists_url":"https://api.github.com/users/thaJeztah/gists{/gist_id}","starred_url":"https://api.github.com/users/thaJeztah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thaJeztah/subscriptions","organizations_url":"https://api.github.com/users/thaJeztah/orgs","repos_url":"https://api.github.com/users/thaJeztah/repos","events_url":"https://api.github.com/users/thaJeztah/events{/privacy}","received_events_url":"https://api.github.com/users/thaJeztah/received_events","type":"User","site_admin":false},"open_issues":18,"closed_issues":21,"state":"open","created_at":"2015-06-05T19:27:06Z","updated_at":"2015-07-17T21:08:44Z","due_on":"2015-08-09T22:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/docker/docker/pulls/13171/commits","review_comments_url":"https://api.github.com/repos/docker/docker/pulls/13171/comments","review_comment_url":"https://api.github.com/repos/docker/docker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/docker/issues/13171/comments","statuses_url":"https://api.github.com/repos/docker/docker/statuses/b5e2fb605d88d63d2a7589970af32a5055f99175","head":{"label":"jlhawn:archive_copy","ref":"archive_copy","sha":"b5e2fb605d88d63d2a7589970af32a5055f99175","user":{"login":"jlhawn","id":1441929,"avatar_url":"https://avatars.githubusercontent.com/u/1441929?v=3","gravatar_id":"","url":"https://api.github.com/users/jlhawn","html_url":"https://github.com/jlhawn","followers_url":"https://api.github.com/users/jlhawn/followers","following_url":"https://api.github.com/users/jlhawn/following{/other_user}","gists_url":"https://api.github.com/users/jlhawn/gists{/gist_id}","starred_url":"https://api.github.com/users/jlhawn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlhawn/subscriptions","organizations_url":"https://api.github.com/users/jlhawn/orgs","repos_url":"https://api.github.com/users/jlhawn/repos","events_url":"https://api.github.com/users/jlhawn/events{/privacy}","received_events_url":"https://api.github.com/users/jlhawn/received_events","type":"User","site_admin":false},"repo":{"id":14341765,"name":"docker","full_name":"jlhawn/docker","owner":{"login":"jlhawn","id":1441929,"avatar_url":"https://avatars.githubusercontent.com/u/1441929?v=3","gravatar_id":"","url":"https://api.github.com/users/jlhawn","html_url":"https://github.com/jlhawn","followers_url":"https://api.github.com/users/jlhawn/followers","following_url":"https://api.github.com/users/jlhawn/following{/other_user}","gists_url":"https://api.github.com/users/jlhawn/gists{/gist_id}","starred_url":"https://api.github.com/users/jlhawn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlhawn/subscriptions","organizations_url":"https://api.github.com/users/jlhawn/orgs","repos_url":"https://api.github.com/users/jlhawn/repos","events_url":"https://api.github.com/users/jlhawn/events{/privacy}","received_events_url":"https://api.github.com/users/jlhawn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jlhawn/docker","description":"Docker - the open-source application container engine","fork":true,"url":"https://api.github.com/repos/jlhawn/docker","forks_url":"https://api.github.com/repos/jlhawn/docker/forks","keys_url":"https://api.github.com/repos/jlhawn/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jlhawn/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jlhawn/docker/teams","hooks_url":"https://api.github.com/repos/jlhawn/docker/hooks","issue_events_url":"https://api.github.com/repos/jlhawn/docker/issues/events{/number}","events_url":"https://api.github.com/repos/jlhawn/docker/events","assignees_url":"https://api.github.com/repos/jlhawn/docker/assignees{/user}","branches_url":"https://api.github.com/repos/jlhawn/docker/branches{/branch}","tags_url":"https://api.github.com/repos/jlhawn/docker/tags","blobs_url":"https://api.github.com/repos/jlhawn/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jlhawn/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jlhawn/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/jlhawn/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jlhawn/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/jlhawn/docker/languages","stargazers_url":"https://api.github.com/repos/jlhawn/docker/stargazers","contributors_url":"https://api.github.com/repos/jlhawn/docker/contributors","subscribers_url":"https://api.github.com/repos/jlhawn/docker/subscribers","subscription_url":"https://api.github.com/repos/jlhawn/docker/subscription","commits_url":"https://api.github.com/repos/jlhawn/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/jlhawn/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/jlhawn/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/jlhawn/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/jlhawn/docker/contents/{+path}","compare_url":"https://api.github.com/repos/jlhawn/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jlhawn/docker/merges","archive_url":"https://api.github.com/repos/jlhawn/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jlhawn/docker/downloads","issues_url":"https://api.github.com/repos/jlhawn/docker/issues{/number}","pulls_url":"https://api.github.com/repos/jlhawn/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/jlhawn/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/jlhawn/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jlhawn/docker/labels{/name}","releases_url":"https://api.github.com/repos/jlhawn/docker/releases{/id}","created_at":"2013-11-12T18:50:12Z","updated_at":"2015-05-06T21:32:40Z","pushed_at":"2015-07-14T17:43:26Z","git_url":"git://github.com/jlhawn/docker.git","ssh_url":"git@github.com:jlhawn/docker.git","clone_url":"https://github.com/jlhawn/docker.git","svn_url":"https://github.com/jlhawn/docker","homepage":"http://www.docker.io","size":61225,"stargazers_count":5,"watchers_count":5,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":5,"default_branch":"master"}},"base":{"label":"docker:master","ref":"master","sha":"e5fa2a740dacc3098371fd39bc86050c40f96504","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":7691631,"name":"docker","full_name":"docker/docker","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/docker","description":"Docker - the open-source application container engine","fork":false,"url":"https://api.github.com/repos/docker/docker","forks_url":"https://api.github.com/repos/docker/docker/forks","keys_url":"https://api.github.com/repos/docker/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/docker/teams","hooks_url":"https://api.github.com/repos/docker/docker/hooks","issue_events_url":"https://api.github.com/repos/docker/docker/issues/events{/number}","events_url":"https://api.github.com/repos/docker/docker/events","assignees_url":"https://api.github.com/repos/docker/docker/assignees{/user}","branches_url":"https://api.github.com/repos/docker/docker/branches{/branch}","tags_url":"https://api.github.com/repos/docker/docker/tags","blobs_url":"https://api.github.com/repos/docker/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/docker/languages","stargazers_url":"https://api.github.com/repos/docker/docker/stargazers","contributors_url":"https://api.github.com/repos/docker/docker/contributors","subscribers_url":"https://api.github.com/repos/docker/docker/subscribers","subscription_url":"https://api.github.com/repos/docker/docker/subscription","commits_url":"https://api.github.com/repos/docker/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/docker/contents/{+path}","compare_url":"https://api.github.com/repos/docker/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/docker/merges","archive_url":"https://api.github.com/repos/docker/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/docker/downloads","issues_url":"https://api.github.com/repos/docker/docker/issues{/number}","pulls_url":"https://api.github.com/repos/docker/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/docker/labels{/name}","releases_url":"https://api.github.com/repos/docker/docker/releases{/id}","created_at":"2013-01-18T18:10:57Z","updated_at":"2015-07-17T22:44:00Z","pushed_at":"2015-07-17T22:38:01Z","git_url":"git://github.com/docker/docker.git","ssh_url":"git@github.com:docker/docker.git","clone_url":"https://github.com/docker/docker.git","svn_url":"https://github.com/docker/docker","homepage":"http://www.docker.com","size":225923,"stargazers_count":23332,"watchers_count":23332,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5790,"mirror_url":null,"open_issues_count":1036,"forks":5790,"open_issues":1036,"watchers":23332,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/13171"},"html":{"href":"https://github.com/docker/docker/pull/13171"},"issue":{"href":"https://api.github.com/repos/docker/docker/issues/13171"},"comments":{"href":"https://api.github.com/repos/docker/docker/issues/13171/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/docker/pulls/13171/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/docker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/docker/pulls/13171/commits"},"statuses":{"href":"https://api.github.com/repos/docker/docker/statuses/b5e2fb605d88d63d2a7589970af32a5055f99175"}}}}