Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Copying file from host to container

Tags:

shell

docker

copy

I am trying to copy a set of files from docker host to container. On a AUFS system directly going into /var/lib/docker/aufs/... works. However I am another system with Fedora that has devicemapper as the storage driver. On this system if I do this:

[root@myhost tmp]# docker inspect -f '{{.Id}}' 393ef4b9f485
393ef4b9f485dafc78037f59bdbeda16d63b8338487248ed25b68cf544f29e24
[root@myhost tmp]# cd /var/lib/docker/devicemapper/mnt/393ef4b9f485dafc78037f59bdbeda16d63b8338487248ed25b68cf544f29e24
[root@myhost 393ef4b9f485dafc78037f59bdbeda16d63b8338487248ed25b68cf544f29e24]# ls -l
total 0
[root@myhost 393ef4b9f485dafc78037f59bdbeda16d63b8338487248ed25b68cf544f29e24]#

I get nothing. I have tried all suggestions from Copying files from host to Docker container

Using tar seems to be great, instead of directly going to the underlying FS. But I cannot assume that tar would be present in all containers.

If it is relevant, I have even tried to create a file in the container, but it and then did a find . -name in /var/lib/docker/devicemapper/mnt to no avail.

Any hints?

EDIT 1: Based on one of the answers, adding these constraints. The intent is to copy files into a container without a. not modify the containers build (Dockerfile), b. To not install any ssh or ftp daemons. and c. not even change the way the container was started.

EDIT 2: Adding the docker info :

# docker info
Containers: 1
Images: 21
Storage Driver: devicemapper
 Pool Name: docker-253:0-397467-pool
 Pool Blocksize: 65.54 kB
 Backing Filesystem: extfs
 Data file:
 Metadata file:
 Data Space Used: 4.261 GB
 Data Space Total: 107.4 GB
 Data Space Available: 103.1 GB
 Metadata Space Used: 3.596 MB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.144 GB
 Udev Sync Supported: true
 Library Version: 1.02.90 (2014-09-01)
Execution Driver: native-0.2
Kernel Version: 3.17.4-301.fc21.x86_64
Operating System: Fedora 21 (Twenty One)
CPUs: 4
Total Memory: 3.86 GiB
Name: fedora-docker

Docker Version is 1.6.0 and container image is based on RHEL.

like image 381
Yogesh_D Avatar asked Apr 29 '15 09:04

Yogesh_D


People also ask

How do I copy a folder from host to container?

Obtain the name or id of the Docker container. Issue the docker cp command and reference the container name or id. The first parameter of the docker copy command is the path to the file inside the container. The second parameter of the docker copy command is the location to save the file on the host.

Which Dockerfile command defines files to copy from the host file system onto the container?

Docker cp Command It can only be used to copy files between the host system and a single container.


Video Answer


1 Answers

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 driver and on Ubuntu with AUFS as the storage driver. Works for me in both the cases.

like image 161
Yogesh_D Avatar answered Oct 19 '22 06:10

Yogesh_D