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

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 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 commented Aug 13, 2013

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

@shykes
Copy link
Contributor

shykes commented Aug 13, 2013

#1221

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

@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 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 commented Sep 19, 2013

Any update on that? Thanks

@maci0
Copy link

maci0 commented Sep 26, 2013

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

@fotinakis
Copy link

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

@william8th
Copy link

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 commented Oct 26, 2013

👍 Would love to have this functionality.

@mike-luminate
Copy link

+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 commented Oct 30, 2013

+1 would like to see this as well.

@creack
Copy link
Contributor

creack commented Nov 6, 2013

ping @crosbymichael

@janinl
Copy link

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

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

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

@anthonydahanne
Copy link
Contributor

@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

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

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 commented Dec 15, 2013

@sunnygleason great tip
+1 for bidirectional cp

@joelcogen
Copy link

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

@fccoelho
Copy link

+1 for scp

@mountainpaul
Copy link

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

@noteed
Copy link

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

+1

2 similar comments
@serkanh
Copy link

serkanh commented Jun 16, 2014

+1

@naftulikay
Copy link

+1

@marcellodesales
Copy link

+1 PLEASE

@vieux
Copy link
Contributor

vieux commented Jul 2, 2014

@marcellodesales issue: #5846
PR #6580

@spothanis
Copy link

+1

@yumitubi
Copy link

Yes! +1

@fsoppelsa
Copy link
Contributor

+1

1 similar comment
@mustafaakin
Copy link
Contributor

+1

@galets
Copy link

galets commented Aug 28, 2014

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

+1

@cerisier
Copy link

+1 =(

@mdedetrich
Copy link

+1

5 similar comments
@MatthewFitchett
Copy link

+1

@giladegozi
Copy link

+1

@mingbowan
Copy link

+1

@PerArneng
Copy link

+1

@lemonjp
Copy link

lemonjp commented Oct 28, 2014

+1

@andrewstuart
Copy link

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 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

Awesome!!

@galets
Copy link

galets commented Oct 29, 2014

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

@xuanmingyi
Copy link

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

copy life folder life into container 5e1ce281984a

@llitfkitfk
Copy link

@xuanmingyi 👍

@dividedmind
Copy link

You can copy files with docker exec:

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

@duglin
Copy link
Contributor

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

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

@diezcode
Copy link

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

@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 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
Development

No branches or pull requests