【问题标题】:How can I load multiple tar images using nerdctl? (containerd)如何使用 nerdctl 加载多个 tar 图像? (容器)
【发布时间】:2022-02-01 15:59:25
【问题描述】:

当前目录下大约有 10 个容器镜像文件,我想将它们加载到使用 containerd 作为 CRI 的 Kubernetes 集群中。

[root@test tmp]# ls -1
test1.tar
test2.tar
test3.tar
...

我尝试使用 xargs 一次加载它们,但得到以下结果:

[root@test tmp]# ls -1 | xargs nerdctl load -i
unpacking image1:1.0 (sha256:...)...done
[root@test tmp]#

第一个 tar 文件加载成功,但命令退出,剩余的 tar 文件没有处理。

我已确认命令 nerdctl load -i 成功,退出代码为 0。

[root@test tmp]# nerdctl load -i test1.tar
unpacking image1:1.0 (sha256:...)...done
[root@test tmp]# echo $?
0

有人知道原因吗?

【问题讨论】:

    标签: docker xargs containerd nerdctl


    【解决方案1】:

    您通过管道传送到xargs 的实际ls 命令被视为单个参数,其中文件名由空字节分隔(简而言之...参见例如this article 以获得更好的深入分析)。如果您的xargs 版本支持它,您可以使用-0 选项来考虑这一点:

    ls -1 | xargs -0 nerdctl load -i
    

    同时,这并不安全,你应该明白为什么it's not a good idea to loop over ls output in your shell

    我宁愿把上面的转换成下面的命令:

    for f in *.tar; do
      nerdctl load -i "$f"
    done
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-15
      • 2019-04-16
      • 1970-01-01
      • 2012-12-01
      • 2017-03-27
      • 1970-01-01
      • 2013-10-22
      • 1970-01-01
      相关资源
      最近更新 更多