将文件从主机复制到容器 [英] Copying file from host to container

查看:172
本文介绍了将文件从主机复制到容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一组文件从docker主机复制到容器。
在直接进入/ var / lib / docker / aufs / ...的AUFS系统上。
但是我是另一个Fedora系统,它具有devicemapper作为存储驱动。
如果我这样做,在这个系统上:

  [root @ myhost tmp]#docker inspect -f'{{ .ID}} 393ef4b9f485 
393ef4b9f485dafc78037f59bdbeda16d63b8338487248ed25b68cf544f29e24
[根@为myhost TMP]#CD的/ var / lib中/搬运工/ devicemapper的/ mnt / 393ef4b9f485dafc78037f59bdbeda16d63b8338487248ed25b68cf544f29e24
[根@为myhost 393ef4b9f485dafc78037f59bdbeda16d63b8338487248ed25b68cf544f29e24]#LS -l
总计0
[root @ myhost 393ef4b9f485dafc78037f59bdbeda16d63b8338487248ed25b68cf544f29e24]#

我什么也没收。
我已经尝试过将文件从主机复制到Docker容器的所有建议



使用tar似乎是伟大的,而不是直接去底层的FS。但是我不能假定tar会存在于所有容器中。



如果相关,我甚至试图在容器中创建一个文件,一个找到。在/ var / lib / docker / devicemapper / mnt中的-name不可用。



任何提示?



编辑1:
根据其中一个答案,添加这些约束。
意图是将文件复制到没有a的容器中。不修改容器build(Dockerfile),b。不要安装任何ssh或ftp守护程序。和c。甚至没有改变容器开始的方式。



编辑2:添加码头信息

 #docker info 
容器:1
图像:21
存储驱动程序:devicemapper
池名称:docker-253:0-397467 -pool
池块大小:65.54 kB
备份文件系统:extfs
数据文件:
元数据文件:
使用的数据空间:4.261 GB
数据空间总计:107.4 GB
可用数据空间:103.1 GB
使用的元数据空间:3.596 MB
元数据空间总计:2.147 GB
可用的元数据空间:2.144 GB
支持Udev同步:true
库版本:1.02.90(2014-09-01)
执行驱动程序:native-0.2
内核版本:3.17.4-301.fc21.x86_64
操作系统:Fedora 21(二十一)
CPU:4
总内存:3.86 GiB
名称:fedora-docker

Docker版本为1.6.0,容器映像基于RHEL。

解决方案

  cd / proc /`docker inspect --format{{.State.Pid已经在Fedora上使用Devicemapper进行了测试,作为存储驱动程序
和Ubuntu上的AUFS作为存储驱动。
在这两种情况下都适用于我。


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.

解决方案

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.

这篇关于将文件从主机复制到容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆