美文网首页
Containerd 的镜像和容器管理

Containerd 的镜像和容器管理

作者: 彩色的炮灰 | 来源:发表于2023-07-02 11:10 被阅读0次

一. 镜像管理:
1. 查看镜像列表:
[root@node2 ~]# ctr images/image/i ls
2. 拉取镜像:
[root@node2 ~]# ctr images pull --platform linux/amd64 docker.io/library/busybox:latest
--platform:指定要拉取得镜像的平台
3. 镜像挂载,把已下载的容器镜像挂载至宿主机的目录中:
命令格式:ctr images mount 镜像名 挂载的目录
[root@node2 ~]# ctr images mount docker.io/library/busybox:latest /mnt
4. 卸载:

[root@node2 ~]# umount /mnt
5. 镜像导出:

下载镜像

[root@node2 ~]# ctr images pull --all-platforms docker.io/library/busybox:latest
 
--all-platforms:表示下载所有平台的busybox:latest镜像
 
## 导出镜像
[root@node2 ~]# ctr images export --all-platforms nginx-alpine.img(导出的文件名) 
docker.io/library/nginx:alpine(要导出的镜像)
  1. 镜像导入:

[root@node2 ~]# ctr images import nginx-alpine.img(要导入的镜像文件)
注意:直接导入镜像可能会出现类似"ctr: content digest sha256:xxxxxxx not found"的错误,因此在拉取和导出镜像时,都要指定" --all-platforms "参数再导入镜像。

  1. 删除镜像:

[root@node2 ~]# ctr images rm docker.io/library/busybox:latest
8. 给镜像打标记tag:

[root@node2 ~]# ctr images tag docker.io/library/busybox:latest busybox:latest
再次查看镜像列表:

二. 容器管理:

  1. 静态容器命令查询:
[root@node2 ~]# ctr containerd --help
[root@node2 ~]# ctr c -h
  1. 查看容器列表:

[root@node2 ~]# ctr container/containers/c ls
3. 查看任务列表:当容器运行起来的时候才会产生任务。

[root@node2 ~]# ctr task/task/t ls
4. 创建静态容器:

[root@node2 ~]# ctr c create busybox:latest busybox
 
[root@node2 ~]# ctr c ls
CONTAINER    IMAGE             RUNTIME                  
busybox      busybox:latest    io.containerd.runc.v2
  1. 启动静态容器,启动task,即表时在容器中运行了进程,即为动态容器。:
[root@node2 ~]# ctr t start -d busybox(容器名)
 
[root@node2 ~]# ctr t ls
TASK       PID     STATUS    
busybox    1510    RUNNING
 
-d:表示daemon或者后台的意思,否则会卡住终端
  1. 进入到动态容器:

[root@node2 ~]# ctr -n default task exec --exec-id $RANDOM -t busybox sh

-n:表示指定命名空间
-t:表示提供一个终端
7. 查看容器详细信息:

[root@node2 ~]# ctr c info busybox
8. 直接运行一个动态容器:

[root@node2 ~]# ctr run -d --net-host busybox:latest busybox2
-d:表示dameon,后台运行
--net-host:表示容器的IP就是宿主机的IP(相当于docker里的host类型网络)

查看容器列表:

[root@node2 ~]# ctr c ls
CONTAINER IMAGE RUNTIME
busybox busybox:latest io.containerd.runc.v2
busybox2 busybox:latest io.containerd.runc.v2

查看任务列表:

[root@node2 ~]# ctr t ls
TASK PID STATUS
busybox 1510 RUNNING
busybox2 1637 RUNNING

进入到容器

[root@node2 ~]# ctr -n default task exec --exec-id $RANDOM -t busybox2 sh

    9.  暂停容器:

[root@node2 ~]# ctr t pause busybox2

[root@node2 ~]# ctr t ls
TASK PID STATUS
busybox 1510 RUNNING
busybox2 1637 PAUSED
10. 恢复容器:

[root@node2 ~]# ctr t resume busybox2

[root@node2 ~]# ctr t ls
TASK PID STATUS
busybox2 1637 RUNNING
busybox 1510 RUNNING
11. 停止容器:

使用kill命令停止容器中运行的进程,既为停止容器

[root@node2 ~]# ctr tasks kill busybox2

查看容器停止后状态,STATUS为STOPPED

TASK PID STATUS
busybox 10660 STOPPED
busybox2 9823 RUNNING
12. 删除容器:

[root@node2 ~]# ctr t delete busybox2 ## 删除已经停止的容器

[root@node2 ~]# ctr t delete -f busybox2 ## 强制删除容器,包括正在运行的容器

查看任务列表:

[root@node2 ~]# ctr t ls
TASK PID STATUS
busybox 1510 RUNNING

查看容器列表:

[root@node2 ~]# ctr c ls
CONTAINER IMAGE RUNTIME
busybox busybox:latest io.containerd.runc.v2
busybox2 busybox:latest io.containerd.runc.v2
13. 查看命名空间列表:

[root@node2 ~]# ctr ns ls
NAME LABELS
default
14. 创建命名空间:

[root@node2 ~]# ctr ns c it(命名空间名称)

[root@node2 ~]# ctr ns ls
NAME LABELS
default
it
15. 删除命名空间:

[root@node2 ~]# ctr ns rm it
————————————————

原文链接:https://blog.csdn.net/NancyLCL/article/details/126905921

相关文章

网友评论

      本文标题:Containerd 的镜像和容器管理

      本文链接:https://www.haomeiwen.com/subject/jhcgydtx.html