Docker Copying file from host to container Docker Copying file from host to container docker docker

Docker Copying file from host to container


UPDATE:Now docker cp command line command works both ways.See the docker cp documentation

Usage

docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-

docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH

=======Original Answer ==============

Found the most easiest way that works across storage drivers:

cd /proc/`docker inspect --format "{{.State.Pid}}" <containerid>`/root

Have tested this on Fedora with Devicemapper as the storage driverand on Ubuntu with AUFS as the storage driver.Works for me in both the cases.


This answer provides you a different view of copying.

1> Use this way provided you know the IP of the container. If your aim is just to take the files form the host system and put it in the container you can do it using different ways. File transfer protocol is a easier way. you can setup an SSH server(sshd) on your docker container and use scp or any other file transfer tools to do it.

2> Sharing files via volumes using this command docker run -ti -v /host-path-of-directory-having-files/:/target-path-in-container/:rw image-name bash. You can refer this link https://docs.docker.com/userguide/dockervolumes/