docker、ctr、crictl命令简介与使用

article/2025/8/12 17:56:11

概述

在使用k3s过程中,经常需要使用ctrcrictl两个命令,本文记录一下。

ctr

类似docker命令是docker-shim容器运行时的客户端工具,ctr是Containerd的客户端工具。一个简单的CLI接口,用作Containerd本身的一些调试用途,投入生产使用时还是应该配合docker或cri-containerd。

安装Containerd作为容器运行时后,会自动安装ctr;安装k3s后,也会自动安装ctr

命名空间

ctrdocker命令一个较大的区别,ctr有命名空间的概念,自带一个moby命名空间:
在这里插入图片描述
如果执行过ctr i pullctr i importctr i export等命令,又没有通过-n参数指定命名空间,则会自动创建default命名空间:
在这里插入图片描述
当Containerd结合k8s(或k3s)使用时,相关镜像一般存放到k8s.io,相关操作需要加-n k8s.io,避免与默认空间混淆,且将参数放到最前面,即:ctr -n=k8s.io i pull

ctr命令输出:

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 pluginsversion                    Print the client and server versionscontainers, c, container   Manage containerscontent                    Manage contentevents, event              Display containerd eventsimages, image, i           Manage imagesleases                     Manage leasesnamespaces, namespace, ns  Manage namespacespprof                      Provide golang pprof outputs for containerdrun                        Run a containersnapshots, snapshot        Manage snapshotstasks, t, task             Manage tasksinstall                    Install a new packageoci                        OCI toolssandboxes, sandbox, sb, s  Manage sandboxesinfo                       Print the server infodeprecationsshim                       Interact with a shim directlyhelp, h                    Shows a list of commands or help for one commandGLOBAL 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

crictl

crictl,GitHub,一个兼容CRI的命令行接口,可用于检查和调试k8s/kubelet节点上的容器运行时和应用程序。只有一个k8s.io命名空间,无需-n参数。

安装

VERSION="v1.33.0"
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-amd64.tar.gz
sudo tar zxvf crictl-$VERSION-linux-amd64.tar.gz -C /usr/local/bin
rm -f crictl-$VERSION-linux-amd64.tar.gz

crictl默认连接到unix:///var/run/dockershim.sock。对于其它运行时,可通过多种方式设置端点:

  • 设置--runtime-endpoint--image-endpoint选项;
  • 设置CONTAINER_RUNTIME_ENDPOINTIMAGE_SERVICE_ENDPOINT环境变量;
  • 在配置文件--config=/etc/crictl.yaml设置端点。

在连接到服务器时,配置文件可指定超时值(timeout–timeout),启用或禁用调试(debug–debug)。

比如在k3s环境下,执行cat /var/lib/rancher/k3s/agent/etc/crictl.yaml输出:

runtime-endpoint: unix:///run/k3s/containerd/containerd.sock

crictl命令输出:

VERSION:v1.31.0-k3s2COMMANDS:attach                 Attach to a running containercheckpoint             Checkpoint one or more running containerscompletion             Output shell completion codeconfig                 Get and set crictl client configuration optionscreate                 Create a new containerevents, event          Stream the events of containersexec                   Run a command in a running containerimagefsinfo            Return image filesystem infoimages, image, img     List imagesinfo                   Display information of the container runtimeinspect                Display the status of one or more containersinspecti               Return the status of one or more imagesinspectp               Display the status of one or more podslogs                   Fetch the logs of a containermetricsp               List pod metrics. Metrics are unstructured key/value pairs gathered by CRI meant to replace cAdvisor's /metrics/cadvisor endpoint.pods                   List podsport-forward           Forward local port to a podps                     List containerspull                   Pull an image from a registryrm                     Remove one or more containersrmi                    Remove one or more imagesrmp                    Remove one or more podsrun                    Run a new container inside a sandboxrunp                   Run a new podruntime-config         Retrieve the container runtime configurationstart                  Start one or more created containersstats                  List container(s) resource usage statisticsstatsp                 List pod statistics. Stats represent a structured API that will fulfill the Kubelet's /stats/summary endpoint.stop                   Stop one or more running containersstopp                  Stop one or more running podsupdate                 Update one or more running containersupdate-runtime-config  Update the runtime configurationversion                Display runtime version informationhelp, h                Shows a list of commands or help for one commandGLOBAL OPTIONS:--config value, -c value                   Location of the client config file. If not specified and the default does not exist, the program's directory is searched as well (default: "/etc/crictl.yaml") [$CRI_CONFIG_FILE]--debug, -D                                Enable debug mode (default: false)--enable-tracing                           Enable OpenTelemetry tracing. (default: false)--image-endpoint value, -i value           Endpoint of CRI image manager service (default: uses 'runtime-endpoint' setting) [$IMAGE_SERVICE_ENDPOINT]--runtime-endpoint value, -r value         Endpoint of CRI container runtime service (default: uses in order the first successful one of [unix:///run/k3s/containerd/containerd.sock unix:///var/run/dockershim.sock unix:///run/containerd/containerd.sock unix:///run/crio/crio.sock unix:///var/run/cri-dockerd.sock]). Default is now deprecated and the endpoint should be set instead. [$CONTAINER_RUNTIME_ENDPOINT]--timeout value, -t value                  Timeout of connecting to the server in seconds (e.g. 2s, 20s.). 0 or less is set to default (default: 2s)--tracing-endpoint value                   Address to which the gRPC tracing collector will send spans to. (default: "127.0.0.1:4317")--tracing-sampling-rate-per-million value  Number of samples to collect per million OpenTelemetry spans. Set to 1000000 or -1 to always sample. (default: -1)--help, -h                                 Show help (default: false)--version, -v                              Print the version (default: false)

crictl pull

可以明确的是:

  • 哪怕当前环境已经下载过docker镜像,使用yaml文件通过vLLM启动大模型时,还是会去下载crictl镜像;
  • 通过crictl下载镜像,和docker下载的镜像,其名字一致;
  • yaml文件里使用dustynv/vllm:0.7.4-r36.4.0-cu128-24.04镜像,等价于docker.io/dustynv/vllm:0.7.4-r36.4.0-cu128-24.04
  • 上面的docker.io就是部署在国外的Docker Hub官方镜像源,国内下载速度非常慢;
  • 可考虑使用国内镜像源,如docker.m.daocloud.io/dustynv/vllmdocker.1ms.run/dustynv/vllm
  • 通过crictl pull下载镜像并没有进度条提示,狠是恶心,只能干等,有时候等了10分钟给你来个提示,只能重试。

在这里插入图片描述
如上图所示,没有任何进度提示。

下载国外镜像,会遇到各种奇奇怪怪的报错:
在这里插入图片描述
使用国内的镜像源地址:
在这里插入图片描述
反复重试,还是上面的报错提示。

Qwen等ChatGPT给出的解决方法是先登录。

好,遇到问题解决问题;打开网站毫秒镜像,使用个人手机号注册。按照Qwen给出的幻觉答复,crictl login
在这里插入图片描述
crictl pull镜像可以执行docker login,可见crictl底层使用的还是docker镜像那一套机制:
在这里插入图片描述
不过又遇到另一个超时报错,那就再换一个国内镜像源吧。

实践下来,通过docker.m.daocloud.io镜像源下载crictl镜像速度还能接受。

crictl镜像和ctr镜像

部分网络资料说crictl image list等效于ctr -n=k8s.io image list

经过各种ChatGPT以及命令尝试:
在这里插入图片描述
crictl image等效于crictl images,等效于crictl image listcrictl images list

在k3s环境下,crictl image等效于k3s ctr -n=k8s.io image list
在这里插入图片描述
k3s命令前缀不能省去。k3s默认使用-n=k8s.io命名空间,因此crictl image等效于k3s ctr images list

个数

crictl images | grep vllm输出2个:
在这里插入图片描述
k3s ctr images list | grep vllm输出4个:
在这里插入图片描述
分析:

  • crictl是CRI客户端工具,crictl输出是CRI提供给kubelet的简化视图,只显示标签信息,不展示digest表示;
  • k3s ctr image输出,表明containerd实际存储四个镜像引用;分别是tag和digest;

crictl镜像导出

输入命令crictl imagesk3s crictl images的截图如下:
在这里插入图片描述
可见,在k3s环境下,crictl命令等价于k3s crictl,也就是说,k3s命令前缀可以省去。

问题在于,一个vLLM镜像动辄5~6个G。

vLLM这篇博客也提到过,部署大模型时,通过k8s调度到从节点,则从节点也需要对应的模型文件和crictl镜像。

那crictl镜像能不能导出为tar包,通过scp命令传输到从节点,然后在从节点导入tar包为crictl镜像呢?

答案当然是可以,docker镜像就完全可以这么玩,crictl和docker存在很多相似之处。

但crictl并没有提供save命令:
在这里插入图片描述
需要通过ctr export命令执行导出操作。

导出镜像的前提是找到镜像,要不然就会出现如下not found报错:
在这里插入图片描述
k3s ctr image | grep vllm:0.8.6输出2行,下面这一行非常非常长,:

docker.io/dustynv/vllm:0.8.6-r36.4-cu128-24.04                                                                   application/vnd.docker.distribution.manifest.v2+json sha256:b2210294b661acc6e94bc302ce5111d6d0cb01a3815ada0132c105f540fb7a63 5.7 GiB   linux/arm64 io.cri-containerd.image=managed
docker.io/dustynv/vllm@sha256:b2210294b661acc6e94bc302ce5111d6d0cb01a3815ada0132c105f540fb7a63                   application/vnd.docker.distribution.manifest.v2+json sha256:b2210294b661acc6e94bc302ce5111d6d0cb01a3815ada0132c105f540fb7a63 5.7 GiB   linux/arm64 io.cri-containerd.image=managed

导出命令:k3s ctr -n k8s.io image export vllm-0.8.6.tar docker.io/dustynv/vllm:0.8.6-r36.4-cu128-24.04。如果
检查:
在这里插入图片描述

docker、crictl及ctr

三个命令行的对比

命令dockercrictl(推荐)ctr
查看容器列表docker pscrictl psctr -n k8s.io c ls
查看容器详情docker inspectcrictl inspectctr -n k8s.io c info
查看容器日志docker logscrictl logs
容器内执行命令docker execcrictl exec
挂载容器docker attachcrictl attach
容器资源使用docker statscrictl stats
创建容器docker createcrictl createctr -n k8s.io c create
启动容器docker startcrictl startctr -n k8s.io run
停止容器docker stopcrictl stop
删除容器docker rmcrictl rmctr -n k8s.io c del
查看镜像列表docker imagescrictl imagesctr -n k8s.io i ls
查看镜像详情docker inspectcrictl inspect
拉取镜像docker pullcrictl pullctr -n k8s.io i pull
推送镜像docker pushctr -n k8s.io i push
删除镜像docker rmicrictl rmictr -n k8s.io i rm
查看Pod列表crictl pods
查看Pod详情crictl inspectp
启动Podcrictl runp
停止Podcrictl stopp
导入镜像docker loadctr -n k8s.io i import
导出镜像docker savectr -n k8s.io i export

http://www.hkcw.cn/article/tEtGfKBGqp.shtml

相关文章

Docker安装mitproxy

一:概述 mitmproxy 是一组工具,可为 HTTP/1、HTTP/2 和 WebSockets 提供支持 SSL/TLS 的交互式拦截代理。 二:安装 2.1 运行并拉取镜像 ocker run --rm -it -p 8080:8080 -p 0.0.0.0:8081:8081 mitmproxy/mitmproxy mitmweb --web-host 0.0…

Linux 简单模拟实现C语言文件流

🌇前言 在 C语言 的文件流中,存在一个 FILE 结构体类型,其中包含了文件的诸多读写信息以及重要的文件描述符 fd,在此类型之上,诞生了 C语言 文件相关操作,如 fopen、fclose、fwrite 等,这些函数…

数据要素×AI:高质量数据集如何成为智能时代的“新石油“

在数字中国建设峰会上,国家数据局提出的"三类高质量数据集"建设规划引发广泛关注。这不仅是技术层面的创新,更是对数据要素价值释放路径的深刻思考。当我们站在AI产业化的关键节点回望,会发现数据正在经历一场从"原料"到…

CCPC dongbei 2025 I

题目链接:https://codeforces.com/gym/105924 题目背景: 给定一个二分图,左图编号 1 ~ n,右图 n 1 ~ 2n,左图的每个城市都会与右图的某个城市犯冲(每个城市都只与一个城市犯冲),除…

如何学习开关电源?从“大”到“小”学习开关电源...

01 / 简介 / 参考 开关电源研学群[BUCK] ,之前创建了开关电源研学群,为电源同行提供学习交流的平台。参考 一种高效的硬件工程师学习方法[更新篇,更牛逼,加量不加价] ,之前也给大家推荐了更加高效的学习方法。 群内有很多电源大佬,经常给大家解答疑问,在此表示感谢;…

C#里与嵌入式系统W5500网络通讯(3)

有与W5500通讯时,需要使用下面的寄存器: PHYCFGR (W5500 PHY Configuration Register) [R/W] [0x002E] [0b10111XXX] PHYCFGR configures PHY operation mode and resets PHY. In addition, PHYCFGR indicates the status of PHY such as duplex, Speed, Link. 这张表格详细…

WEB3——开发者怎么查看自己的合约日志记录

在区块链中查看合约的日志信息(也叫事件 logs),主要有以下几种方式,具体方法依赖于你使用的区块链平台(如 Ethereum、BSC、Polygon 等)和工具(如 Etherscan、web3.js、ethers.js、Hardhat 等&am…

【深度学习】17. 深度生成模型:DCGAN与Wasserstein GAN公式深度推导

深度生成模型:DCGAN与Wasserstein GAN公式深度推导 深度卷积生成对抗网络 DCGAN 在原始 GAN 框架中,生成器和判别器通常使用全连接层构建,这限制了模型处理图像的能力。为此,Radford 等人在 2016 年提出了 DCGAN(Deep Convoluti…

Scratch节日 | 六一儿童节射击游戏

六一儿童节快乐!这款超有趣的 六一儿童节射击游戏,让你变身小猫弓箭手,守护节日的快乐时光! 🎮 游戏玩法 上下方向键:控制小猫的位置,自由移动,瞄准目标! 空格键&#…

IDEA PyCharm 等工具如何同时打开多个窗口

目录 1.第一步:打开软件通过左上角 File 进入到 Settings 2.第二步:进入 Settings 后选择 System Settings 3.第三步:新建项目时可以选择 此窗口(This Window) 或 新窗口(New Window) 1.第一步:打开软件通过左上角 File 进入到…

2024年09月 C/C++(四级)真题解析#中国电子学会#全国青少年软件编程等级考试

C/C++编程(1~8级)全部真题・点这里 第1题:有几个PAT 字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位,第 4 位(A),第 6 位(T);第二个 PAT 是第 3 位,第 4 位(A),第 6 位(T)。 现给定字符串,问一共可以形成多少个 PAT? 时间限制:1000 内存限制:26214…

【echarts】仪表盘

<div style"width:50%;height:33%"><Yibiaopan echart_id"ybpChart2" :series_data"gaugeData2" title"火电" unit"MWh" :colorList"[#DFA58F,#F89061,#FF8E59]" /></div> 链接&#xff1a;ht…

目标检测我来惹1 R-CNN

目标检测算法&#xff1a; 识别图像中有哪些物体和位置 目标检测算法原理&#xff1a; 记住算法的识别流程、解决问题用到的关键技术 目标检测算法分类&#xff1a; 两阶段&#xff1a;先区域推荐ROI&#xff0c;再目标分类 region proposalCNN提取分类的目标检测框架 RC…

【AI学习】检索增强生成(Retrieval Augmented Generation,RAG)

1&#xff0c;介绍 出自论文《Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks》&#xff0c;RAG是权宜之计&#xff0c;通过RAG将问题简单化、精简化、剔除噪声&#xff0c;让LLM更容易理解、生成内容。RAG&#xff1a;检索增强技术检索生成&#xff08;重…

LINUX 61 rsync定时同步;软链接

定时同步报错 [rootbackup ~]# cat rsync_java.sh !/bin/bash rsync -av user3192.168.235.10::app /backup/app1_java &&/dev/null [rootbackup ~]# cd /backup [rootbackup backup]# ls app1_java [rootbackup backup]# cd app1_java [rootbackup app1_java]# ls 1.…

[Android] APK安装器 V20160330-6.0

【应用名称】APK安装【应用版本】V20160330-6.0版本【软件大小】154KB【适用型号】安卓【应用说明】此版本兼容性极强&#xff0c;Android6-Android15都可以用&#xff0c;兼容平板和手机&#xff0c;已经过测试&#xff01; 软件优点&#xff1a; 不占内存&#xff0c;大小比…

017搜索之深度优先搜索——算法备赛

深度优先搜索 如果说广度优先搜索是逐层扩散&#xff0c;那深度优先搜索就是一条道走到黑。 深度优先遍历是用递归实现的&#xff0c;预定一条顺序规则&#xff08;如上下左右顺序&#xff09; &#xff0c;一直往第一个方向搜索直到走到尽头或不满足要求后返回上一个叉路口按…

电子电路:时钟脉冲与上升沿的详细解析

一、时钟脉冲的量子物理本质 1. 电磁波能量量子化 时钟脉冲本质是电磁能量的周期性传递,其最小能量单元为: E = h f E = hf E=hf 其中 h = 6.626 10 − 34 J ⋅ s h=6.62610^{-34} \ Js h=6.62610−34 J⋅s(普朗克常数), f f f 为时钟频率。当3GHz CPU运行时,单个时…

HTTPS

HTTPS 是什么 它其实就是网站的保镖版 HTTP。平常你用普通HTTP上网&#xff0c;你浏览器和网站服务器之间传的东西&#xff0c;不管是密码、聊天内容还是信用卡号&#xff0c;都是“裸奔”的&#xff0c;谁都能半路偷看或者篡改。 HTTPS 就不同了&#xff0c;它在你们开始传东…

LTSPICE仿真电路:(三十)压流变换器

1.压流转换器&#xff08;NPN型三极管&#xff09; 压流转换器&#xff1a;将电压转换为电流信号。 直接看仿真 这个电路是负反馈电路&#xff0c;分析使用续断虚短&#xff0c;输入信号是3V&#xff0c;所以在Rset电阻处的电压始终是3V &#xff0c;Uce为6V&#xff08;发射…