containerd 环境下容器操作手册

B站影视 欧美电影 2025-09-19 13:45 1

摘要:在没有 Docker 的环境里,容器由containerd管理。在 Kubernetes 场景下,容器一般位于 k8s.io namespace 下。本文档总结常用命令与操作方法,便于日常运维。

在没有 Docker 的环境里,容器由 containerd 管理。
在 Kubernetes 场景下,容器一般位于 k8s.io namespace 下。
本文档总结常用命令与操作方法,便于日常运维。

sudo ctr -n k8s.io c ls

列出运行中的任务:

sudo ctr -n k8s.io t lssudo ctr -n k8s.io tasks attach

或者查看宿主机日志文件:

sudo tail -f /var/log/containers/sudo ctr -n k8s.io tasks exec -t --exec-id debug$$/bin/sh

⚠️ --exec-id 必须唯一,可随便取,如 debug$$。

sudo crictl exec -it/bin/sh

⚠️ 注意:

按镜像名过滤:

sudo ctr -n k8s.io c ls | grep nginx

按 Pod 名过滤:

sudo ctr -n k8s.io c ls | grep myapp-podfunction cexec { name=$1 id=$(sudo ctr -n k8s.io c ls | grep $name | awk '{print $1}' | head -n1) if [ -z "$id" ]; then echo "Container not found!" return 1 fi sudo ctr -n k8s.io t exec -t --exec-id shell$$ $id /bin/sh}

用法:

function clogs { name=$1 logfile=$(ls /var/log/containers | grep $name | head -n1) if [ -z "$logfile" ]; then echo "Log file not found!" return 1 fi sudo tail -f /var/log/containers/$logfile}

用法:

来源:linux运维菜

相关推荐