Skip to content
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 #905

Closed
ysimonson opened this issue Jun 17, 2013 · 74 comments
Closed

Moving a file from the host system to a container #905

ysimonson opened this issue Jun 17, 2013 · 74 comments

Comments

@ysimonson
Copy link

@ysimonson ysimonson commented Jun 17, 2013

I want to move a file from the host file system to a container. How do I do this?

I tried docker insert, but there doesn't seem to be much documentation on it, and it doesn't appear to support copying local sources. Both of these commands didn't insert anything into /root:

docker insert image file:///path/to/file /root/file
docker insert image /path/to/file /root/file

...or return any indication or error for that matter. Also tried feeding the contents in from stdin, like so:

`docker run -i -t image cat \> /root/file` < /path/to/file

But that didn't work either.

@vieux
Copy link
Contributor

@vieux vieux commented Jun 17, 2013

Hi,

For now insert only takes distant URL not local, like docker insert base https://raw.github.com/dotcloud/docker/cf1b5bd529016a4963589bdabebeab43893880b9/container.go /api.go

The thing you are trying to do can be done in a docker file with the add command.

This will be changed soon.

@shykes
Copy link
Contributor

@shykes shykes commented Aug 13, 2013

@crosbymichael this is solved by "docker cp" right?

@shykes
Copy link
Contributor

@shykes shykes commented Aug 13, 2013

@ghost ghost assigned crosbymichael Aug 13, 2013
@crosbymichael
Copy link
Contributor

@crosbymichael crosbymichael commented Aug 13, 2013

@shykes no, cp does a copy from a contain to the host. It would not be too difficult to allow you to copy both ways with scp like syntax.

I'm sure I could implement this just in time for 0.6 ;)

@shykes
Copy link
Contributor

@shykes shykes commented Aug 13, 2013

I'll leave you judge of what should go higher in the list for 0.6. Just make sure to optimize for what people need :)

@solomonstre
@getdocker

On Tue, Aug 13, 2013 at 2:55 PM, Michael Crosby notifications@github.com
wrote:

@shykes no, cp does a copy from a contain to the host. It would not be too difficult to allow you to copy both ways with scp like syntax.

I'm sure I could implement this just in time for 0.6 ;)

Reply to this email directly or view it on GitHub:
#905 (comment)

@karellm
Copy link

@karellm karellm commented Sep 19, 2013

Any update on that? Thanks

@maci0
Copy link

@maci0 maci0 commented Sep 26, 2013

yeah, i would be interested in that as well, cp should work bi-directional

@fotinakis
Copy link

@fotinakis fotinakis commented Sep 26, 2013

+1, having docker cp support host to container copies would be very helpful!

@william8th
Copy link

@william8th william8th commented Oct 1, 2013

Having a command to inject files into an image locally would help a lot. Beginners can start without having to write a Dockerfile to be able to perform this.

@icco
Copy link

@icco icco commented Oct 26, 2013

👍 Would love to have this functionality.

@mike-luminate
Copy link

@mike-luminate mike-luminate commented Oct 30, 2013

+1, having docker cp support host-to-container copies solves a lot of problems and keeps the command line api simple and predictable.

@filmaj
Copy link

@filmaj filmaj commented Oct 30, 2013

+1 would like to see this as well.

@creack
Copy link
Contributor

@creack creack commented Nov 6, 2013

@janinl
Copy link

@janinl janinl commented Nov 8, 2013

Not the ideal solution, but one can use "docker run -v /hostMountPoint:/containerMountPoint ..." to copy files across.

@mike-luminate
Copy link

@mike-luminate mike-luminate commented Nov 8, 2013

Yes, that is the workaround I have been using as well. In fact, I have
ditched dockerfiles completely and now use a simple suite of auto-cleaning
shell scripts. I end up with smaller images and less layers.

On Fri, Nov 8, 2013 at 6:14 AM, Lilian notifications@github.com wrote:

Not the ideal solution, but one can use "docker run -v
/hostMountPoint:/containerMountPoint ..." to copy files across.


Reply to this email directly or view it on GitHubhttps://github.com//issues/905#issuecomment-28065043
.

@willfarrell
Copy link

@willfarrell willfarrell commented Nov 8, 2013

I solved this by adding sshd to my containers then using rsync to update the files.

@anthonydahanne
Copy link
Contributor

@anthonydahanne anthonydahanne commented Nov 30, 2013

@janinl hello could you please explicit this docker run -v command ? what if I want to copy my.file from the host current directory to the i /opt/ directory of the image named 'base' ?
thanks in advance !

@anthonydahanne
Copy link
Contributor

@anthonydahanne anthonydahanne commented Nov 30, 2013

nevermind, I found it : if I want to copy license.key in the host's /home/vagrant to the container's /opt here is the line :
sudo docker run -v /home/vagrant:/mnt anthonydahanne/openjdk7 cp /mnt/license.key /opt/

@sunnygleason
Copy link

@sunnygleason sunnygleason commented Dec 5, 2013

one trick I used recently to avoid restarting the container was netcat "nc"

in the container: nc -l 10101 > thefile.bin
on the host: cat thefile.bin | nc 172.0.2.3 10101
(where 172.0.2.3 is the container ip, and 10101 is a random port of your choosing)

I then do sha1sum in both places to make sure it arrived ok...

@kunthar
Copy link

@kunthar kunthar commented Dec 15, 2013

@sunnygleason great tip
+1 for bidirectional cp

@joelcogen
Copy link

@joelcogen joelcogen commented Dec 22, 2013

I would love to see a scp-like syntax for docker cp!

@fccoelho
Copy link

@fccoelho fccoelho commented Jan 13, 2014

+1 for scp

@mountainpaul
Copy link

@mountainpaul mountainpaul commented Jan 13, 2014

@sunnygleason. Thanks. I would also +1 for scp.

@noteed
Copy link

@noteed noteed commented Jan 22, 2014

@crosbymichael Any update on this one ? Maybe a few pointers about how to implement it if someone feels like it ?

I would love to be able to have HAProxy or Nginx reload its configuration (which would be injected prior to the reload by docker cp).

@FranciscoCanas
Copy link

@FranciscoCanas FranciscoCanas commented Jun 5, 2014

+1

2 similar comments
@serkanh
Copy link

@serkanh serkanh commented Jun 16, 2014

+1

@naftulikay
Copy link

@naftulikay naftulikay commented Jun 16, 2014

+1

@marcellodesales
Copy link

@marcellodesales marcellodesales commented Jul 2, 2014

+1 PLEASE

@vieux
Copy link
Contributor

@vieux vieux commented Jul 2, 2014

@spothanis
Copy link

@spothanis spothanis commented Aug 6, 2014

+1

@le087
Copy link

@le087 le087 commented Aug 13, 2014

Yes! +1

@fsoppelsa
Copy link
Contributor

@fsoppelsa fsoppelsa commented Aug 14, 2014

+1

1 similar comment
@mustafaakin
Copy link
Contributor

@mustafaakin mustafaakin commented Aug 25, 2014

+1

@galets
Copy link

@galets galets commented Aug 28, 2014

seriously... more than a year, and the feature is not there?

+1

@cerisier
Copy link

@cerisier cerisier commented Sep 18, 2014

+1 =(

@mdedetrich
Copy link

@mdedetrich mdedetrich commented Sep 28, 2014

+1

5 similar comments
@MatthewFitchett
Copy link

@MatthewFitchett MatthewFitchett commented Sep 28, 2014

+1

@giladegozi
Copy link

@giladegozi giladegozi commented Sep 30, 2014

+1

@mingbowan
Copy link

@mingbowan mingbowan commented Oct 2, 2014

+1

@PerArneng
Copy link

@PerArneng PerArneng commented Oct 9, 2014

+1

@lemonjp
Copy link

@lemonjp lemonjp commented Oct 28, 2014

+1

@andrewstuart
Copy link

@andrewstuart andrewstuart commented Oct 29, 2014

With docker exec you can now run something like netcat inside the container to accept external files. Not a complete docker cp solution but definitely a usable workaround.

@galets
Copy link

@galets galets commented Oct 29, 2014

Yay!!! finally.

Version 1.3.0

New command: docker exec

The new docker exec command lets you run a process in an existing, active container. The command has APIs for both the daemon and the client. With docker exec, you'll be able to do things like add or remove devices from running containers, debug running containers, and run commands that are not part of the container's static specification. Details in the command line reference.

@davidlcarroll9
Copy link

@davidlcarroll9 davidlcarroll9 commented Oct 29, 2014

Awesome!!

@galets
Copy link

@galets galets commented Oct 29, 2014

finally I got to patch my bashes, i was putting it off forever

@xuanmingyi
Copy link

@xuanmingyi xuanmingyi commented Apr 29, 2015

tar -cf - life|docker exec -i 5e1ce281984a /bin/tar -C /root/ -xf -

copy life folder life into container 5e1ce281984a

@llitfkitfk
Copy link

@llitfkitfk llitfkitfk commented May 15, 2015

@dividedmind
Copy link

@dividedmind dividedmind commented Aug 9, 2015

You can copy files with docker exec:

cat foo | docker exec -i $container bash -c 'cat > /foo'

@duglin
Copy link
Contributor

@duglin duglin commented Aug 9, 2015

Actually, the latest docker has support for "docker cp" from host into
container :-)

On Sat, Aug 8, 2015 at 11:26 PM, Rafał Rzepecki notifications@github.com
wrote:

You can copy files with docker exec:

cat foo | docker exec -i $container bash -c 'cat > /foo'


Reply to this email directly or view it on GitHub
#905 (comment).

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Aug 9, 2015

For reference; this is implemented in #13171 and will be in the docker 1.8.0 release (as @duglin mentioned)

@diezcode
Copy link

@diezcode diezcode commented Feb 4, 2016

How can I copy a file or directory from my HOST /home/myself to an active running container like containername = test1? ok sorry for that

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Feb 4, 2016

@diezcode see #13171. Please keep in mind that the GitHub issue tracker is not a support forum; such questions are better asked on IRC, in the #docker channel, on forums.docker.com, or the docker-user mailinglist

@param0091
Copy link

@param0091 param0091 commented Dec 7, 2017

i'm trying to copy .bak file (10 gb) from host to container using docker cp command but it never completed in mac system .Any solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet