containerとホストとの間のファイルコピー

1090 ワード

http://www.cnblogs.com/lemonbar/p/4060136.html
1.containerからホスト(host)まで
docker cpコマンドを使う
docker cp <containerId>:/file/path/within/container /host/path/target
たとえばmysqlをインストールしてから、my.cnfにコピーします。
docker cp 088ea61c775a:/etc/my.cnf /home/pandy/docker/mysql/
2.ホストからcontainerまで
Get container name or shart container id:
docker ps
Get full container id
docker inspect-f'{.Id}'SHRT_CONTAINER_ID-or-ONTAINER_NAME
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
d 8 e 703 d 7 e 303 soldleon/ssh:latest/usr/sbin/sshd-D cranky_pare
$docker inspect-f'{.Id}'cranky_pare
or
$docker inspect-f'{.Id}'d 8 e 703 d 7 e 303
d 8 e 703 d 7 e 3039 a 6 df 6 d 01 b 58 d 882 e 595 eb 16 c 4 b 83 cf 91847 f 88 e 5
sudo cp file.txt/var/lib/docker/aufs/mnt/d 8 e 703 d 7 e 3039 a 6 df 6 d 01 bd 58 d 882 e 592 eb 16 c 4 b 83 c 91847 f 88 e 5/root/file.txt