ctr打tag

作者:Administrator 发布时间: 2024-11-22 阅读量:12 评论数:0

ctr打tag

问题

以前使用docker习惯了,突然发现crictl是无法打tag的

需求

一个阿里云镜像 registry.aliyuncs.com/k8sxio/pause:3.6 ,用 crictl 命令下载后,需要改成registry.k8s.io/pause:3.6 供k8s集群使用

原因

  • 语法
    crictl 没有tag选项,只能用ctr命令打tag

解决

先上答案

ctr -n k8s.io i tag  registry.aliyuncs.com/k8sxio/pause:3.6 registry.k8s.io/pause:3.6

下载镜像

[root@k3s-test ~]# crictl pull registry.aliyuncs.com/k8sxio/pause:3.6

当然也可以用ctr命令下载

[root@k3s-test ~]# ctr images pull registry.aliyuncs.com/k8sxio/pause:3.6

查看下载结果

[root@k3s-test ~]# crictl images
IMAGE                                        TAG                    IMAGE ID            SIZE
docker.io/rancher/klipper-helm               v0.7.3-build20220613   38b3b9ad736af       239MB
docker.io/rancher/klipper-lb                 v0.3.5                 dbd43b6716a08       8.51MB
docker.io/rancher/local-path-provisioner     v0.0.21                fb9b574e03c34       35.3MB
docker.io/rancher/mirrored-coredns-coredns   1.9.1                  99376d8f35e0a       49.7MB
docker.io/rancher/mirrored-library-busybox   1.34.1                 7a80323521ccd       1.47MB
docker.io/rancher/mirrored-library-traefik   2.6.2                  72463d8000a35       103MB
docker.io/rancher/mirrored-metrics-server    v0.5.2                 f73640fb50619       65.7MB
docker.io/rancher/mirrored-pause             3.6                    6270bb605e12e       686kB
harbocto.xxx.com.cn/public/rancher-agent     v2.6.9                 b59bfa0f5068b       220MB
registry.aliyuncs.com/k8sxio/pause           3.6                    6270bb605e12e       302kB

如上可见,最后一个镜像是我们刚下载的

查看ctr的namespace
注意,这和k8s/k3s的namespace不是同一概念。

[root@k3s-test ~]# ctr namespace ls
NAME    LABELS 
default        
k8s.io         
moby    

如上可见,有三个namespace——k8s.io(实际上,k8s和k3s使用的都是这个命名空间)。

用ctr命令打tag

[root@k3s-test ~]# ctr -n k8s.io i tag  registry.aliyuncs.com/k8sxio/pause:3.6 registry.k8s.io/pause:3.6

registry.k8s.io/pause:3.6 

ctr命令查看结果

[root@k3s-test ~]# ctr -n k8s.io images ls |grep pause

ctr -n k8s.io images ls |grep pause
registry.aliyuncs.com/k8sxio/pause:3.6                                                                                                  application/vnd.docker.distribution.manifest.list.v2+json sha256:3d380ca8864549e74af4b29c10f9cb0956236dfb01c40ca076fb6c37253234db 294.7 KiB linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x,windows/amd64     io.cri-containerd.image=managed,io.cri-containerd.pinned=pinned 
registry.aliyuncs.com/k8sxio/pause@sha256:3d380ca8864549e74af4b29c10f9cb0956236dfb01c40ca076fb6c37253234db                              application/vnd.docker.distribution.manifest.list.v2+json sha256:3d380ca8864549e74af4b29c10f9cb0956236dfb01c40ca076fb6c37253234db 294.7 KiB linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x,windows/amd64     io.cri-containerd.image=managed,io.cri-containerd.pinned=pinned 
registry.k8s.io/pause:3.6                                                                                                               application/vnd.docker.distribution.manifest.list.v2+json sha256:3d380ca8864549e74af4b29c10f9cb0956236dfb01c40ca076fb6c37253234db 294.7 KiB linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x,windows/amd64     io.cri-containerd.image=managed,io.cri-containerd.pinned=pinned 

crictl命令查看结果

[root@k3s-test ~]# crictl images
IMAGE                                        TAG                    IMAGE ID            SIZE
docker.io/rancher/klipper-helm               v0.7.3-build20220613   38b3b9ad736af       239MB
docker.io/rancher/klipper-lb                 v0.3.5                 dbd43b6716a08       8.51MB
docker.io/rancher/local-path-provisioner     v0.0.21                fb9b574e03c34       35.3MB
docker.io/rancher/mirrored-coredns-coredns   1.9.1                  99376d8f35e0a       49.7MB
docker.io/rancher/mirrored-library-busybox   1.34.1                 7a80323521ccd       1.47MB
docker.io/rancher/mirrored-library-traefik   2.6.2                  72463d8000a35       103MB
docker.io/rancher/mirrored-metrics-server    v0.5.2                 f73640fb50619       65.7MB
docker.io/rancher/mirrored-pause             3.6                    6270bb605e12e       686kB
docker.io/rancher/rancher-agent              v2.6.9                 b59bfa0f5068b       220MB
harbocto.xxx.com.cn/public/rancher-agent     v2.6.9                 b59bfa0f5068b       220MB
registry.aliyuncs.com/k8sxio/pause           3.6                    6270bb605e12e       302kB
registry.k8s.io/pause                        3.6                    6270bb605e12e       302kB

如上可见,ID为 6270bb605e12e的镜像多了一个tag

  • 示例
ctr -n k8s.io i tag  registry.aliyuncs.com/k8sxio/pause:3.6 registry.k8s.io/pause:3.6

参考链接:https://blog.csdn.net/xingzuo_1840/article/details/128833061

评论