如何使用 nerdctl 加载多个 tar 图像? (容器)
How can I load multiple tar images using nerdctl? (containerd)
当前目录下大约有 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
有谁知道原因吗?
您实际的 ls
命令通过管道传输到 xargs
被视为单个参数,其中文件名由空字节分隔(简而言之...参见 this article 的示例更好地 in-depth 分析)。如果你的 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
当前目录下大约有 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
有谁知道原因吗?
您实际的 ls
命令通过管道传输到 xargs
被视为单个参数,其中文件名由空字节分隔(简而言之...参见 this article 的示例更好地 in-depth 分析)。如果你的 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