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
Moving a file from the host system to a container via docker cp #5846
Comments
+1 |
3 similar comments
+1 |
+1 |
+1 |
This there a reason why this cannot be accomplished with an ADD in the Dockerfile? |
@crosbymichael I think the difference here is that Interactively adding/updating a file in a running container can be very convenient, other options (running sshd, volumes, FTP?) could work, but won't be appropriate in many cases. |
Do you have an example of some file you would copy into a running container? |
(Trying to provide a reasonable example here; at this moment I'm using docker for development-environments and use volumes to share files between the host and container) I'm thinking of configuration-files that may change during the lifetime of a container; sometimes you don't want to shutdown or re-build a container to change that. @crosbymichael Is it ok if I reverse the question? Are there any particular reasons to not implement copying to the container? The point is, that at this moment there is (afaik) no way to 'enter' a container to make small changes (interactively) without installing a service for that (e.g. sshd). Docker 'enter' (nsenter?) isn't ready yet (or at least only considered for debugging). |
@crosbymichael I was thinking about implementing an Ansible connection plugin for Docker. Currently, if you want to use Ansible to configure a Docker container, you need to run an ssh server insde the container or you need to install Ansible inside of the container itself. With a connection plugin, you wouldn't need to do either of these things. To implement an Ansible connection plugin, you need to be able to:
This feature is the missing element. I know this can be worked around using |
@thaJeztah The reason why i dont want to implement this is be cause ADD works well and can be reproduce to make image over a over. It's not one off command the modifies the container state. |
@crosbymichael I think I get the point; in some perspective, containers should be built once (preferably via a Dockerfile) and regarded an immutable, deployable 'package'. To make changes, the container should be rebuilt and committed. While this is a reasonable assumption for production purposes (and for deployment), my use case is a bit different; We use dockers to create development environment/sandboxes. Specifications of those environments are not always pre-defined and may need some tweaking / modifications. Having to stop/rebuild a container for each change (to make use of Being able to use I hope my information is useful! |
@lorin +1 to the ansible plugin. |
+1 |
1 similar comment
+1 |
@lorin +1 for the ansible plugin as well. |
+1. Begging please for this. Sometimes I just need to add one tiny file to learn how to make a container work... almost REPL-like functionality if you think about it. |
+1 |
without this feature, people resort to copying into /var/lib/docker/aufs/mnt/ directly (eg, http://stackoverflow.com/questions/22907231/copying-files-from-host-to-docker-container) |
+1 highly support |
+1 Need to copy SSH keys temporarily to the container to clone a private repo. |
+1 on that. |
+1, this is my number one feature request for docker |
For example, I have a docker container that has taken the place of a server I use to run a reporting server. For the most part it works well. The pain in the neck though is each time users run they need to add configuration files. I have one container container for oracle-xe where I used a volume. This works well for oracle-xe I'm happy just setting up one folder and using with every container made from that image. However, it is not an adequate solution for my reporting tool server. For the reporting tool, I really don't want copying data onto one container to impact another container. So that means creating a new folder for every container, doing a chattr on that folder so SELinux allows it to be used as a volume, keeping track what folder is mapped to which container, and clean-up of those folders when they are no longer used. Yuck! Currently I use scp for the reporting tool. From within the container I scp to and from 172.17.41.1. That works, but is again a pain as it means repeatedly typing in my login credentials, as the container doesn't even know what user is running it, let alone that user's private keys. This approach means I can never use the container in a non-interactive mode... "docker cp" offers a great alternative for copying data out of the container, but there really is no good way to get the data into the container. Certainly I could create a new image each time. But that means each and every time I create a new container, I also have to create a new Dockerfile, do a new build, and clean-up the new image when I'm done. Yuck. Certainly I could write a script to do all of this. But then since the script is not part of the container, it breaks the pattern that I should just be able to run my image everywhere. Currently if I don't want to use scp, I can run my image anywhere, after manually installing and hacking a bunch of scripts to maintain per container images or volumes. |
From my point of view, the feature addresses a huge usability issue with docker builds: prototyping sucks.And prototyping is a really important part of the image design process for docker. The best way to find out is trying it out. I am not even a little bit interested going through an entire docker build JUST because my prototyping requires copying over a handful of configuration files or a script that I didn't realize I needed 5 minutes ago. Like others have mentioned we've hacked around this by using ssh and scp but that's way overkill. allowing me to docker cp arbitrary files into a running container neatly addresses that concern. |
Agree that the main time this is needed is during prototyping. You have your container running and you quickly need to add something while trying to get the build correct. Right now you would have to add ssh and have that started and then have it removed from the final build. This I believe falls into the same space as nsenter. |
+1 as well. For me I need the same thing as @tanmaig, I want to copy a temporary ssh key into the container that isn't known when the container image is built. |
@comron The workaround I figured is that you just mount a data volume from the host to the computer. Then run SSH from the host computer etc, and copy data/git clone into the volume and it'll be available in the docker container. I guess the key idea behind not having the 'cp from host to container' is to force the stateless-ness of a docker. |
The workaround way by +1 for the PR to extend |
It looks like #13171 is likely to be approved. One of the things that is problematic with the docker exec solution, is I find sometimes docker exec kills the container when exiting. As such is best avoided for running services. |
@docbill |
+1 This is a very much appreciated feature for development. Although it is not the best practice for deployment! Please let the experienced users choose themselves!! |
e.g. use case: copy mongo dump from host to mongo container in order to restore the data |
+1 This would especially be useful for data-only containers, where you might want to copy in a new configuration or private key. |
+1 to merge and set milestone. |
+1 I need it like right now at this moment |
+1 This would be handy. I need it as well for a production app we're building. |
+1 on this as it's really must have feature for me, for now as a workaround, i transfer the file via stdin of "docker exec" REST API call, but it's not convenient |
The pull requests implementing this are currently on the roadmap for 1.8; see #14058 and #13171. (That's no guarantee that they will make it though) |
🎉 be sure to try out the Release Candidate for Docker 1.8 when it comes out! |
Congrats Josh!!! -Doug Sent from my iPhone
|
+1 congrats. Been watching this thing for a long time now. :) -Erik
|
👍 congrats! |
The
docker cp
command can currently copy a file from the container to the host. It should also be able to do the reverse.Ping @crosbymichael
The text was updated successfully, but these errors were encountered: