Containerd 常用命令
镜像操作
查看镜像
ctr -n k8s.io images list拉取镜像
ctr -n k8s.io images pull <image_url>
# ctr -n k8s.io images pull --user <用户名>:<密码> registry.example.com/image:tag给镜像重新打标签
ctr -n k8s.io images tag <old_tag> <new_tag>导入镜像
ctr -n k8s.io images import <image.tar>导出镜像
# 1. 导出为普通 .tar 文件
ctr -n k8s.io images export nginx.tar docker.io/library/nginx:latest
# 2. 用 gzip 压缩
gzip nginx.tar # 生成 nginx.tar.gz
# 一步到位
ctr -n k8s.io images export - <image.tar> | gzip > image.tar.gz容器操作
查看所有容器(包括运行中和已停止的)
ctr -n k8s.io containers list仅查看运行中的容器
ctr -n k8s.io tasks list查看容器的详细信息
ctr -n k8s.io containers info <容器ID或名称>查看容器的日志
ctr -n k8s.io tasks logs <容器ID或名称>实时查看日志(类似 docker logs -f)
ctr -n k8s.io tasks -f logs <容器ID或名称>查看容器的进程
ctr -n k8s.io tasks ps <容器ID或名称>1. 创建并启动新容器
ctr run -d <镜像名称> <容器名称>
# -d:后台运行(类似 Docker 的 -d)。ctr run -d docker.io/library/nginx:latest nginx启动容器(从现有容器启动)
ctr tasks start <容器ID或名称>ctr tasks start nginx2. 停止容器
ctr tasks kill <容器ID或名称>强制停止(发送 SIGKILL):
ctr tasks kill -s SIGKILL nginx优雅停止(发送 SIGTERM,默认):
ctr tasks kill nginx3. 重启容器
ctr 没有直接重启命令,需先停止再启动:
ctr tasks kill nginx && ctr tasks start nginx4. 删除容器
删除已停止的容器
ctr containers delete <容器ID或名称>ctr containers delete nginx强制删除运行中的容器
先停止任务,再删除容器:
ctr tasks kill nginx && ctr containers delete nginx5. 其他常用操作
查看容器列表
ctr containers list # 所有容器
ctr tasks list # 运行中的容器进入容器(需借助 runc)
runc exec -it <容器ID> sh
Last updated