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

Comments

Projects
None yet
@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

This comment has been minimized.

Collaborator

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

This comment has been minimized.

Collaborator

shykes commented Aug 13, 2013

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

@shykes

This comment has been minimized.

Collaborator

shykes commented Aug 13, 2013

@ghost ghost assigned crosbymichael Aug 13, 2013

@crosbymichael

This comment has been minimized.

Member

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

This comment has been minimized.

Collaborator

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

This comment has been minimized.

karellm commented Sep 19, 2013

Any update on that? Thanks

@maci0

This comment has been minimized.

maci0 commented Sep 26, 2013

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

@fotinakis

This comment has been minimized.

fotinakis commented Sep 26, 2013

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

@william8th

This comment has been minimized.

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

This comment has been minimized.

icco commented Oct 26, 2013

👍 Would love to have this functionality.

@mike-luminate

This comment has been minimized.

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

This comment has been minimized.

filmaj commented Oct 30, 2013

+1 would like to see this as well.

@creack

This comment has been minimized.

Contributor

creack commented Nov 6, 2013

@janinl

This comment has been minimized.

janinl commented Nov 8, 2013

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

@mike-luminate

This comment has been minimized.

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

This comment has been minimized.

willfarrell commented Nov 8, 2013

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

@anthonydahanne

This comment has been minimized.

Contributor

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

This comment has been minimized.

Contributor

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

This comment has been minimized.

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

This comment has been minimized.

kunthar commented Dec 15, 2013

@sunnygleason great tip
+1 for bidirectional cp

@joelcogen

This comment has been minimized.

joelcogen commented Dec 22, 2013

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

@fccoelho

This comment has been minimized.

fccoelho commented Jan 13, 2014

+1 for scp

@mountainpaul

This comment has been minimized.

mountainpaul commented Jan 13, 2014

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

@noteed

This comment has been minimized.

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

jvermillard added a commit to jvermillard/docker that referenced this issue Feb 1, 2014

Fix moby#905 : insert files
by adding support for adding file url support to
the "docker insert" command

Docker-DCO-1.1-Signed-off-by: Julien Vermillard <jvermillar@sierrawireless.com> (github: jvermillard)

jvermillard added a commit to jvermillard/docker that referenced this issue Feb 1, 2014

Fix moby#905 : insert files
by adding support for adding file url support to
the "docker insert" command

Docker-DCO-1.1-Signed-off-by: Julien Vermillard <jvermillar@sierrawireless.com> (github: jvermillard)

jvermillard added a commit to jvermillard/docker that referenced this issue Feb 4, 2014

Fix moby#905 : insert files
by adding support for adding file url support to
the "docker insert" command

Docker-DCO-1.1-Signed-off-by: Julien Vermillard <jvermillar@sierrawireless.com> (github: jvermillard)
@FranciscoCanas

This comment has been minimized.

FranciscoCanas commented Jun 5, 2014

+1

2 similar comments
@serkanh

This comment has been minimized.

serkanh commented Jun 16, 2014

+1

@naftulikay

This comment has been minimized.

naftulikay commented Jun 16, 2014

+1

@marcellodesales

This comment has been minimized.

marcellodesales commented Jul 2, 2014

+1 PLEASE

@vieux

This comment has been minimized.

Collaborator

vieux commented Jul 2, 2014

@spothanis

This comment has been minimized.

spothanis commented Aug 6, 2014

+1

@le087

This comment has been minimized.

le087 commented Aug 13, 2014

Yes! +1

@fsoppelsa

This comment has been minimized.

Contributor

fsoppelsa commented Aug 14, 2014

+1

1 similar comment
@mustafaakin

This comment has been minimized.

Contributor

mustafaakin commented Aug 25, 2014

+1

@galets

This comment has been minimized.

galets commented Aug 28, 2014

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

+1

@cerisier

This comment has been minimized.

cerisier commented Sep 18, 2014

+1 =(

@mdedetrich

This comment has been minimized.

mdedetrich commented Sep 28, 2014

+1

5 similar comments
@MatthewFitchett

This comment has been minimized.

MatthewFitchett commented Sep 28, 2014

+1

@giladegozi

This comment has been minimized.

giladegozi commented Sep 30, 2014

+1

@mingbowan

This comment has been minimized.

mingbowan commented Oct 2, 2014

+1

@PerArneng

This comment has been minimized.

PerArneng commented Oct 9, 2014

+1

@lemonjp

This comment has been minimized.

lemonjp commented Oct 28, 2014

+1

@andrewstuart

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

davidlcarroll9 commented Oct 29, 2014

Awesome!!

@galets

This comment has been minimized.

galets commented Oct 29, 2014

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

@xuanmingyi

This comment has been minimized.

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

This comment has been minimized.

llitfkitfk commented May 15, 2015

@dividedmind

This comment has been minimized.

dividedmind commented Aug 9, 2015

You can copy files with docker exec:

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

@duglin

This comment has been minimized.

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

This comment has been minimized.

Member

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

This comment has been minimized.

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

This comment has been minimized.

Member

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

This comment has been minimized.

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