New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker cp to, from, and between containers #10198
Conversation
@SvenDowideit Please take a look at the updated docs commit 👍 |
The command will always fail if the `SRC_PATH` resource does not exist or if | ||
the parent directory of `DST_PATH` does not exist. | ||
|
||
> It is not possible to copy certain system files such as resources under |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be formatted as a **note:**
Also, are there limitations wrt copying to/from volumes? If there are, they should be mentioned here (possible as a second/separate. "Note")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be formatted as a
**note:**
Ah, thanks! I forgot that part from the style guide.
Also, are there limitations wrt copying to/from volumes? If there are, they should be mentioned here (possible as a second/separate. "Note")
Yeah, I think I included a part about this in the man page docs for it. I'll include it here too. I don't think the man articles are included on the website.
Closing for now until I get time to rebase and update. |
Documented changes to API to enable new `docker cp` behavior. Added documentation on `docker cp` usage and behavior. Fixed up the docs/man/README.md file a bit. Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
Adds TarResource and CopyTo functions to be used for creating archives for use with the new `docker cp` behavior. Adds multiple test cases for the CopyFrom and CopyTo functions in the pkg/archive package. Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
dab4c1f
to
f9dfd54
Compare
Adds new jobs for handling uploading or downloading an archive of container content or copying files and directories between containers. Also adds ability to stat a resource in a container rootfs or mounted volume. To be used by the API for new endpoints making new `docker cp` behavior possible. Uses new pkg/archive utilities for archiving filesystem contents especially for this purpose. Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
f9dfd54
to
fd1a3b6
Compare
|
||
// CmdCp handles copying files or directories to/from/across containers. | ||
func (cli *DockerCli) CmdCp(args ...string) error { | ||
cmd := cli.Subcmd("cp", "[SRC_CONTAINER:]SRC_PATH [DST_CONTAINER:]DST_PATH", "Copy files between containers or a local path", true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this will fail on windows due to the colon. Sadly we can't even assume that a container name longer than a single char isn't a drive on windows because technically you can identify a container by just a single char.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, I don't know how else to solve it except to check the length of the container ID/name and assume that if its equal to 1 then its a drive letter. Not perfect but it should be pretty rare that people only use a single char to reference containers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will Windows Paths also use slashes, or back-slashes? i.e. a regular path on Windows will be C:\some\host\path
. But, yes, this will become an issue if Windows containers are going to be supported I guess (I suspect that will still be far in the future)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a current issue that probably wont be fixed by this PR: #9932
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, I thought I remembered an issue. Guess this won't be the only location where docker will break on Windows, so not my biggest concern 😃
New endpoints have been added for copying to, from, and between containers. These endpoints call out to jobs registered by the daemon for handling each of these cases. Also added an endpoint to stat a filesystem resource in a container. Each handler uses a common error handling function for errors from these jobs before returning an error, if any. To be used by CLI for changes to `docker cp`. Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
Utilizes new Remote API endpoints to handle copying to, from, and between containers in a manner that matches other common Unix utilities like `cp` and `scp`. Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
Adds several integration tests for `docker cp` behavior with over a dozen tests for each of: container -> local local -> container container -> container Also adds several more integration tests with `docker cp` when volumes are involved in the paths which are being copied. Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
Fixes moby#9787 Signed-off-by: Brian Goff <cpuguy83@gmail.com>
fd1a3b6
to
1d86684
Compare
+1 on design for adding to remote API @tiborvass do PRs in design review need rebase before moving to code review? @jlhawn can you add a TL;DR design description in the comment instead of just pointing to the documentation commit. The documentation commit is very detailed. |
@dmcgowan you're right, they don't need a rebase if it's in design review. My bad.
Also when specifying a file from a container, are we making sure the path is always absolute? I think we should do that, that way The idea is to prevent having If we can agree on only allowing absolute paths for paths within containers, then the algorithm for detecting Let me know if you guys agree with that at least. |
Will people try to run docker.exe inside Git Bash on Windows? (does that work?) I think that uses |
@thaJeztah is quoting the only option to escape spaces? I imagine the unix method of using a |
@dmcgowan hm, I'll have to check (escaping), but only run Windows at work, so not a Windows machine at hand right now |
Looks like a caret |
@dmcgowan @thaJeztah don't forget that what counts from the code's perspective, is what gets passed to os.Args after the shell did its escaping. Also |
Ah, true! The "Git Bash" console might still be something to take into account though. |
I'd like to agree on having filepaths from containers always be absolute so that we can give the following definition: |
+1 |
I'm just wondering.... and I don't mean to derail things but.... if I'm remembering correctly this will not fully support scp-like action. For example, I don't think it support wildcards, do I have that right @jlhawn ? It got me thinking that it would be a lot easier to just support scp itself. This could mean two things:
And it just works. All files, links, etc.... are copied into my container at /tmp. Of course the hard part is that we need to make sure the target container is running and supports tar. But in reality we could just turn archive.go into tar if we really wanted. Anyway, I guess what I'm wondering if whether we want to simplify this to just be add an API to "untar an incoming tarball into a container" (and we could of course, later look to do the reverse). |
Right. While your shell would do expansion on a local source file/dir, it doesn't support copying multiple sources to a destination directory (though we could certainly add this without much difficulty), and of course we have no way to auto complete sources that are in a container. |
since we already have a 'cp' API to extract files as a tarball, I kind of like doing this slowly and adding the ability to put a tarball into a container. And, I wouldn't mind changing the 'cp' API to take wildcards :-) But once we have those two APIs we can then look at what it takes to do the cp between containers. One concern with this current PR is that it will only copy between containers on the same host, right? Which means swarm won't be happy. If we implemented (at first) "cp between containers" as the semantic equivalent of : |
I've talked to @vieux about this in the past and he mentioned that he kind of liked that it's a separate API endpoint so that they can implement it in a way that makes sense for swarm. |
Is this in effort to reduce the ambiguity with Windows drive specifiers? like |
@jlhawn how about we do that in another PR? It would just be a small convenient feature. We could move on with this PR then. |
+1 on moving forward with this PR! |
ping @docker/core-maintainers for design review |
I agree with myself: #10198 (comment) and #10198 (comment) :) So +1 to that |
I'm moving development of this feature to a new PR #13171 and closing this one. I'll also be reducing the feature set:
These things can be added later. The goal is: well-behaved copy operations that work more like @cpuguy83's PR #13125 may be a good alternative but it doesn't resolve the strange behavior where |
hello, I just started with docker and I would like to know how to duplicate an application in a container to be able to depliyer it in another container? |
You'd normally build an image with the application, and start two containers from that image.
… On 17 Jan 2019, at 12:32, sidiki9 ***@***.***> wrote:
hello, I just started with docker and I would like to know how to duplicate an application in a container to be able to depliyer it in another container?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
can you show me the procesuce? I am on ubuntu 18.04.1 |
please check the first commit with documentation changes for details
fixes #5846