容器与主机之间数据拷贝
描述
isula cp 用于容器与主机之间的数据拷贝。
用法
isula cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH
isula cp [OPTIONS] SRC_PATH CONTAINER:DEST_PATH
参数
cp命令支持参数参考下表。
表 1 cp命令参数列表
约束限制
iSulad在执行拷贝时,不会挂载/etc/hostname, /etc/resolv.conf,/etc/hosts三个文件,也不会对—volume和—mount参数传入的参数挂载到host,所以对这些文件的拷贝使用的是镜像中的原始文件,而不是真实容器中的文件。
[root@localhost tmp]# isula cp b330e9be717a:/etc/hostname /tmp/hostname
[root@localhost tmp]# cat /tmp/hostname
[root@localhost tmp]#
iSulad在解压文件时,不会对文件系统中即将被覆盖的文件或文件夹做类型判断,而是直接覆盖,所以在拷贝时,如果源为文件夹,同名的文件会被强制覆盖为文件夹;如果源为文件,同名的文件夹会被强制覆盖为文件。
[root@localhost tmp]# rm -rf /tmp/test_file_to_dir && mkdir /tmp/test_file_to_dir
[root@localhost tmp]# isula exec b330e9be717a /bin/sh -c "rm -rf /tmp/test_file_to_dir && touch /tmp/test_file_to_dir"
[root@localhost tmp]# isula cp b330e9be717a:/tmp/test_file_to_dir /tmp
[root@localhost tmp]# ls -al /tmp | grep test_file_to_dir
-rw-r----- 1 root root 0 Apr 26 09:59 test_file_to_dir
- iSulad 在cp拷贝过程中,会将容器freeze住,在拷贝完成后,恢复容器运行。
示例
将主机/test/host目录拷贝到容器21fac8bb9ea8的/test目录下。
isula cp /test/host 21fac8bb9ea8:/test
将容器21fac8bb9ea8的/www目录拷贝到主机的/tmp目录中。
isula cp 21fac8bb9ea8:/www /tmp/