docker和主机之间文件复制

从容器内拷贝文件到主机上


docker cp <containerId>:/file/path/within/container /host/path/target

 

 

从主机上拷贝文件到容器内方法一

1.获取容器名称或者id :
docker ps

2. 获取整个容器的id
docker inspect -f '{{.Id}}' 容器的ID或者容器名(步骤1中获取的名或者ID)

3.在主机上拷贝文件:

sudo cp path-file-host /var/lib/docker/aufs/mnt/FULL_CONTAINER_ID/PATH-NEW-FILE
或者
$ sudo cp path-file-host /var/lib/docker/devicemapper/mnt/123abc<<id>>/rootfs/root

 

如:sudo cp file.txt /var/lib/docker/aufs/mnt/容器整个ID (步骤2中获取的ID)

 

从主机上拷贝文件到容器内方法二:

 

用输入输出符

docker run -i ubuntu /bin/bash -c 'cat > /path/to/container/file' < /path/to/host/file/
或者
docker exec -it <container_id> bash -c 'cat > /path/to/container/file' < /path/to/host/file/

 

从主机上拷贝文件到容器内方法三:

docker run -v /path/to/hostdir:/mnt $container
在容器内拷贝
cp /mnt/sourcefile /path/to/destfile

posted on 2017-10-20 11:29  yanmay  阅读(36)  评论(0编辑  收藏  举报

导航