[Docker]——container和主机(host)之间的文件拷贝

1. 从 container 到 主机(host)

使用 docker cp 命令

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

 

2. 从 主机(host) 到 container

  1. Get container name or short container id :

    docker ps

  2. Get full container id

    docker inspect -f '{{.Id}}' SHORT_CONTAINER_ID-or-CONTAINER_NAME

  3. copy file :

    sudo cp path-file-host /var/lib/docker/aufs/mnt/FULL_CONTAINER_ID/PATH-NEW-FILE

EXAMPLE :

$docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

d8e703d7e303 solidleon/ssh:latest /usr/sbin/sshd -D cranky_pare

$docker inspect -f '{{.Id}}' cranky_pare

or

$docker inspect -f '{{.Id}}' d8e703d7e303

d8e703d7e3039a6df6d01bd7fb58d1882e592a85059eb16c4b83cf91847f88e5

$sudo cp file.txt /var/lib/docker/aufs/mnt/d8e703d7e3039a6df6d01bd7fb58d1882e592a85059eb16c4b83cf91847f88e5/root/file.txt

posted @ 2014-10-29 17:44  lemon_bar  阅读(14306)  评论(1编辑  收藏  举报