容器与主机之间数据拷贝

描述

isula cp 用于容器与主机之间的数据拷贝。

用法

  1. isula cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH
  2. isula cp [OPTIONS] SRC_PATH CONTAINER:DEST_PATH

参数

cp命令支持参数参考下表。

表 1 cp命令参数列表

命令

参数

说明

cp

-H, —host

指定要连接的iSulad socket文件路径

约束限制

  • iSulad在执行拷贝时,不会挂载/etc/hostname, /etc/resolv.conf,/etc/hosts三个文件,也不会对—volume和—mount参数传入的参数挂载到host,所以对这些文件的拷贝使用的是镜像中的原始文件,而不是真实容器中的文件。

    1. [root@localhost tmp]# isula cp b330e9be717a:/etc/hostname /tmp/hostname
    2. [root@localhost tmp]# cat /tmp/hostname
    3. [root@localhost tmp]#
  • iSulad在解压文件时,不会对文件系统中即将被覆盖的文件或文件夹做类型判断,而是直接覆盖,所以在拷贝时,如果源为文件夹,同名的文件会被强制覆盖为文件夹;如果源为文件,同名的文件夹会被强制覆盖为文件。

    1. [root@localhost tmp]# rm -rf /tmp/test_file_to_dir && mkdir /tmp/test_file_to_dir
    2. [root@localhost tmp]# isula exec b330e9be717a /bin/sh -c "rm -rf /tmp/test_file_to_dir && touch /tmp/test_file_to_dir"
    3. [root@localhost tmp]# isula cp b330e9be717a:/tmp/test_file_to_dir /tmp
    4. [root@localhost tmp]# ls -al /tmp | grep test_file_to_dir
    5. -rw-r----- 1 root root 0 Apr 26 09:59 test_file_to_dir
  • iSulad 在cp拷贝过程中,会将容器freeze住,在拷贝完成后,恢复容器运行。

示例

将主机/test/host目录拷贝到容器21fac8bb9ea8的/test目录下。

  1. isula cp /test/host 21fac8bb9ea8:/test

将容器21fac8bb9ea8的/www目录拷贝到主机的/tmp目录中。

  1. isula cp 21fac8bb9ea8:/www /tmp/