不用 docker!containerd 镜像 crctl 命令一把梭

文章目录

Containerd容器镜像管理

帮助命令

  • docker使用docker images命令管理镜像
  • 单机containerd使用ctr images命令管理镜像,containerd本身的CLI
  • k8s中containerd使用crictl images命令管理镜像,Kubernetes社区的专用CLI工具
bash 复制代码
#命令帮助

# 查看ctr命令帮助信息,了解可用的子命令和全局选项
[root@localhost ~]# ctr --help
NAME:
ctr -
__
_____/ /______
/ ___/ __/ ___/
/ /__/ /_/ /
\___/\__/_/
containerd CLI
USAGE:
ctr [global options] command [command options] [arguments...]
VERSION:
v1.6.32
DESCRIPTION:
ctr is an unsupported debug and administrative client for interacting
with the containerd daemon. Because it is unsupported, the commands,
options, and operations are not guaranteed to be backward compatible or
stable from release to release of the containerd project.
COMMANDS:
plugins, plugin            provides information about containerd plugins
version                    print the client and server versions
containers, c, container   manage containers
content                    manage content
events, event              display containerd events
images, image, i           manage images
leases                     manage leases
namespaces, namespace, ns  manage namespaces
pprof                      provide golang pprof outputs for containerd
run                        run a container
snapshots, snapshot        manage snapshots
tasks, t, task             manage tasks
install                    install a new package
oci                        OCI tools
deprecations
shim                       interact with a shim directly
help, h                    Shows a list of commands or help for one command
GLOBAL OPTIONS:
--debug                      enable debug output in logs
--address value, -a value    address for containerd's GRPC server (default:
"/run/containerd/containerd.sock") [$CONTAINERD_ADDRESS]
--timeout value              total timeout for ctr commands (default: 0s)
--connect-timeout value      timeout for connecting to containerd (default:
0s)
--namespace value, -n value  namespace to use with commands (default:
"default") [$CONTAINERD_NAMESPACE]
--help, -h                   show help
--version, -v                print the version

# 查看ctr images镜像管理子命令的帮助信息
[root@localhost ~]# ctr images --help
NAME:
ctr images - manage images
USAGE:
ctr images command [command options] [arguments...]
COMMANDS:
check                    check existing images to ensure all content is
available locally
export                   export images
import                   import images
list, ls                 list images known to containerd
mount                    mount an image to a target path
unmount                  unmount the image from the target
pull                     pull an image from a remote
push                     push an image to a remote
delete, del, remove, rm  remove one or more images by reference
tag                      tag an image
label                    set and clear labels for an image
convert                  convert an image
OPTIONS:
--help, -h  show help

查看镜像

bash 复制代码
# 使用images子命令查看镜像列表(list)
[root@docker ~]# ctr images list
REF TYPE DIGEST SIZE PLATFORMS LABELS

# 使用images子命令查看镜像列表(ls为list的简写)
[root@docker ~]# ctr images ls
REF TYPE DIGEST SIZE PLATFORMS LABELS

# 使用image子命令查看镜像列表(list)
[root@docker ~]# ctr image list
REF TYPE DIGEST SIZE PLATFORMS LABELS

# 使用image子命令查看镜像列表(ls为list的简写)
[root@docker ~]# ctr image ls
REF TYPE DIGEST SIZE PLATFORMS LABELS

# 使用i子命令查看镜像列表(i为images的简写)
[root@docker ~]# ctr i list
REF TYPE DIGEST SIZE PLATFORMS LABELS

# 使用i子命令查看镜像列表(i和ls均为简写)
[root@docker ~]# ctr i ls
REF TYPE DIGEST SIZE PLATFORMS LABELS

下载镜像

containerd支持oci标准的镜像,所以可以直接使用docker官方或dockerfile构建的镜像

bash 复制代码
# 使用ctr拉取nginx镜像,需写完整的镜像仓库地址(不能直接写nginx:alpine)
[root@localhost ~]# ctr images pull 054b8ac70e8010d90f2ac00ef29e6580.mirror.swr.myhuaweicloud.com/library/nginx:latest

# 验证现象
# 使用image子命令查看镜像列表(ls为list的简写)
[root@localhost ~]# ctr image ls
REF
TYPE                                    DIGEST
SIZE     PLATFORMS
LABELS
054b8ac70e8010d90f2ac00ef29e6580.mirror.swr.myhuaweicloud.com/library/nginx:latest application/vnd.oci.image.index.v1+json
sha256:84ec966e61a8c7846f509da7eb081c55c1d56817448728924a87ab32f12a72fb 68.9 MiB
linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x,unknown/unknown -

镜像挂载

方便查看镜像中包含的内容

bash 复制代码
# 将nginx镜像挂载到/mnt目录,方便查看镜像中包含的内容
[root@localhost ~]# ctr images mount 054b8ac70e8010d90f2ac00ef29e6580.mirror.swr.myhuaweicloud.com/library/nginx:latest /mnt
sha256:3c1159cd77f83ede793fc21502ae30b39b04378b6b1b625451d701d555cc1cb9
/mnt

# 查看挂载目录/mnt中的内容
[root@localhost ~]# ls /mnt
bin  boot  dev  docker-entrypoint.d  docker-entrypoint.sh  etc  home  lib  lib64
media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

# 卸载已挂载的/mnt目录
[root@localhost ~]# umount /mnt

镜像导出

bash 复制代码
# 导出nginx镜像为nginx.tar文件,--platform指定导出linux/amd64平台镜像
[root@localhost ~]# ctr i export --platform linux/amd64 nginx.tar
054b8ac70e8010d90f2ac00ef29e6580.mirror.swr.myhuaweicloud.com/library/nginx:latest

# 查看当前目录下的文件
[root@localhost ~]# ls
nginx.tar

镜像删除

bash 复制代码
# 查看ctr image rm删除镜像命令的帮助
[root@localhost ~]# ctr image rm --help
NAME:
ctr images delete - remove one or more images by reference
USAGE:
ctr images delete [command options] [flags] <ref> [<ref>, ...]
DESCRIPTION:
remove one or more images by reference
OPTIONS:
--sync  Synchronously remove image and all associated resources

# 删除指定的nginx镜像
[root@localhost ~]# ctr image rm 054b8ac70e8010d90f2ac00ef29e6580.mirror.swr.myhuaweicloud.com/library/nginx:latest
054b8ac70e8010d90f2ac00ef29e6580.mirror.swr.myhuaweicloud.com/library/nginx:latest

# 验证现象
# 使用image子命令查看镜像列表(ls为list的简写)
[root@localhost ~]# ctr image ls
REF TYPE DIGEST SIZE PLATFORMS LABELS

镜像导入

bash 复制代码
# 导入nginx.tar镜像文件,--platform指定导入linux/amd64平台镜像
[root@localhost ~]# ctr images import --platform linux/amd64 nginx.tar
unpacking
054b8ac70e8010d90f2ac00ef29e6580.mirror.swr.myhuaweicloud.com/library/nginx:latest
(sha256:84ec966e61a8c7846f509da7eb081c55c1d56817448728924a87ab32f12a72fb)...done

# 验证现象
# 使用image子命令查看镜像列表(ls为list的简写)
[root@localhost ~]# ctr image ls
REF
TYPE                                    DIGEST
SIZE     PLATFORMS
LABELS
054b8ac70e8010d90f2ac00ef29e6580.mirror.swr.myhuaweicloud.com/library/nginx:latest application/vnd.oci.image.index.v1+json
sha256:84ec966e61a8c7846f509da7eb081c55c1d56817448728924a87ab32f12a72fb 68.9 MiB
linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x,unknown/unknown -

修改镜像tag

054b8ac70e8010d90f2ac00ef29e6580.mirror.swr.myhuaweicloud.com/library/nginx:latest 修改为 nginx:latest

bash 复制代码
# 为镜像修改标签,将长镜像名打上nginx:latest标签
[root@localhost ~]# ctr images tag 054b8ac70e8010d90f2ac00ef29e6580.mirror.swr.myhuaweicloud.com/library/nginx:latest nginx:latest
nginx:latest

# 验证现象
# 使用image子命令查看镜像列表(ls为list的简写)
[root@localhost ~]# ctr image ls
REF
TYPE                                    DIGEST
SIZE     PLATFORMS
LABELS
054b8ac70e8010d90f2ac00ef29e6580.mirror.swr.myhuaweicloud.com/library/nginx:latest application/vnd.oci.image.index.v1+json
sha256:84ec966e61a8c7846f509da7eb081c55c1d56817448728924a87ab32f12a72fb 68.9 MiB
linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x,unknown/unknown -
nginx:latest
application/vnd.oci.image.index.v1+json
sha256:84ec966e61a8c7846f509da7eb081c55c1d56817448728924a87ab32f12a72fb 68.9 MiB
linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x,unknown/unknown -
相关推荐
周先生FullStack2 小时前
Mac + 容器本地 MySQL/Redis 环境搭建与网络原理实战
java·spring boot·微服务·容器·架构·个人开发
Dovis(誓平步青云)2 小时前
突破 32 位瓶颈:64 位 XID 如何化解事务号回卷危机
运维·服务器·人工智能·docker·容器
闲云自留地3 小时前
nerdctl 实战全解:替代 docker 的 containerd 客户端,镜像 / 容器 / 网络 / 存储 / Namespace 一把抓
容器
容器魔方4 小时前
基于 KubeEdge 为云边协同 AI 流数据分析提供基础设施
大数据·云原生·容器·开源·边缘计算
九皇叔叔14 小时前
Kubernetes 核心概念:集群架构、核心组件与资源对象
docker·容器·kubernetes·k8s
wdfk_prog19 小时前
ROS教程07:从 ros::start() 顺着源码读懂 Master、XML-RPC 与 Topic 注册发现
运维·缓存·docker·容器·ros
两点王爷21 小时前
常用的 Docker 镜像拉取地址仓库及常用命令详解
运维·服务器·容器
wdfk_prog21 小时前
用 Git Submodule + Sparse Checkout 管理 RT-Thread:内核、BSP、第三方库与业务代码分层实践
运维·缓存·docker·容器·ros
努力努力再努力wz21 小时前
【Docker入门系列】镜像为什么能复用?一文吃透 Docker Image、Registry、运行时架构与常用命令
缓存·docker·容器