kbsonlong
约 500 字 预计阅读 1 分钟
Containerd常用命令
crictl 常用命令
查看所有容器
查看运行中的容器详细信息
1
| crictl inspect [CONTAINER_ID_OR_NAME]
|
进入容器内部执行命令
1
| crictl exec -it CONTAINER_ID bash
|
拉取镜像
1
| crictl pull <image-name>:<tag>
|
列出已下载的镜像
创建并启动容器
1
2
3
| cat pod-config.json | crictl runp # 创建PodSandbox
crictl create --pod POD_ID CONTAINER_CONFIG_PATH # 创建容器
crictl start CONTAINER_ID # 启动容器
|
停止并删除容器
1
2
| crictl stop CONTAINER_ID
crictl rm CONTAINER_ID
|
清理未使用的镜像和沙箱
1
2
| crictl rmi IMAGE_ID # 删除指定镜像
crictl pods --quiet | xargs crictl rm # 删除所有已停止的PodSandboxes
|
Pull指定账号密码
1
| crictl pull --creds username:password registry.kbsonlong.com/sysreport:latest
|
ctr 常用命令
查看容器列表
1
| ctr -n <namespace> containers ls
|
运行容器
1
2
3
4
5
| ctr -n k8s.io run --id <container-id> --net-host --null-io -d \
--env PASSWORD=$drone_password \
--mount type=bind,src=/etc,dst=/host-etc,options=rbind:rw \
--mount type=bind,src=/root/.kube,dst=/root/.kube,options=rbind:rw \
$image sysreport bash /sysreport/run.sh
|
这条命令在指定命名空间下运行一个新的容器,并且:
- –id: 指定容器ID。
- –net-host: 使用主机网络模式。
- –null-io: 将容器的标准输入、输出和错误重定向到 /dev/null。
- -d: 后台运行容器。
- –env: 设置环境变量。
- –mount: 绑定挂载宿主机目录到容器内。
ctr 查看运行中的容器详细信息
1
| ctr -n <namespace> container info <container-id>
|
启动/停止容器
1
2
3
4
5
| # 启动容器
ctr -n <namespace> task start <container-id>
# 停止容器
ctr -n <namespace> task stop <container-id>
|
删除容器
1
| ctr -n <namespace> rm <container-id>
|
ctr 拉取镜像
1
| ctr image pull <registry>/<repository>:<tag>
|
列出所有镜像
清理垃圾数据