一、Containerd 镜像操作

1 基本参数

[root@ecs-65685 ~]# ctr c
NAME:
ctr containers - manage containers USAGE:
ctr containers command [command options] [arguments...] COMMANDS:
create create container
delete, del, remove, rm delete one or more existing containers
info get info about a container
list, ls list containers
label set and clear labels for a container
checkpoint checkpoint a container
restore restore a container from checkpoint OPTIONS:
--help, -h show help

2 镜像操作

在containerd中拉取docker的相关镜像也需要补全。

containerd支持oci标准的镜像,所以可以直接使用docker官方或dockerfile构建的镜像。

--platform 选项指定对应平台的镜像。当然对应的也有推送镜像的命令 ctr image push,如果是私有镜像则在推送的时候可以通过 --user 来自定义仓库的用户名和密码。

拉取镜像添加了--all-platforms会将所有平台都下载下来(amd64 、arm、386 、ppc64le ),否则默认下载当前平台。

拉取镜像可以使用 ctr image pull 来完成,比如拉取 Docker Hub 官方镜像 nginx:alpine,需要注意的是镜像地址需要加上 docker.io Host 地址。

 ctr i pull docker.io/library/nginx:alpine --all-platforms

3 查看镜像

  • 查看镜像可以使用 i 或者image

  • -q 只打印镜像名称

ctr i ls
ctr i ls -q

4 检测本地镜像

[root@ecs-65685 ~]# ctr image check
REF TYPE DIGEST STATUS SIZE UNPACKED
docker.io/library/nginx:alpine application/vnd.docker.distribution.manifest.list.v2+json sha256:b87c350e6c69e0dc7069093dcda226c4430f3836682af4f649f2af9e9b5f1c74 complete (7/7) 9.7 MiB/9.7 MiB true

主要查看其中的 STATUScomplete 表示镜像是完整可用的状态。

5 tag重新打标签

[root@ecs-65685 ~]# ctr i tag docker.io/library/nginx:alpine docker.io/library/nginx:nginxxyz
docker.io/library/nginx:nginxxyz
[root@ecs-65685 ~]# ctr i ls -q
docker.io/library/nginx:alpine
docker.io/library/nginx:nginxxyz # 新增tag

6 删除镜像

使用:delete, del, remove, rm remove one or more images by reference。都可以进行删除。

[root@ecs-65685 ~]# ctr i rm docker.io/library/nginx:nginxxyz
docker.io/library/nginx:nginxxyz
[root@ecs-65685 ~]# ctr i ls -q
docker.io/frps9/tools:SynologyNAS
docker.io/library/nginx:alpine

7 mount镜像

mount镜像实际上将镜像中的文件,挂载到宿主机的目录中去。

mount参数系统为只读状态,只可以读取,不可以写入数据。

使用--rw Enable write support on the mount 可以开启只读。

[root@ecs-65685 ~]# mkdir /home/xyz
[root@ecs-65685 ~]# ctr i ls -q
docker.io/library/nginx:alpine
[root@ecs-65685 ~]# ctr i mount docker.io/library/nginx:alpine /home/xyz/
sha256:26bec62cc7fc1f93f810d51c3f51291dae2d0f9e192e054cc61d1914365003d8
/home/xyz/
[root@ecs-65685 ~]# ls /home/xyz
bin docker-entrypoint.d etc lib mnt proc run srv tmp var
dev docker-entrypoint.sh home media opt root sbin sys usr

mount卸载

[root@ecs-65685 ~]# ctr i unmount /home/xyz
/home/xyz
[root@ecs-65685 ~]# ls /home/xyz

8 推送镜像

[root@ecs-65685 ~]# ctr i push -k docker.io/library/nginx:alpine
index-sha256:b87c350e6c69e0dc7069093dcda226c4430f3836682af4f649f2af9e9b5f1c74: waiting |--------------------------------------|
elapsed: 0.1 s total: 0.0 B (0.0 B/s)
ctr: content digest sha256:36f21d30317cff60a6ab8328cca93dbe554020ba0320c78e964040512d0f27a0: not found

跳过ssl验证--skip-verify, -k skip SSL certificate validation。

9 导入导出

  • import
  • export
  • 默认export导出的为OCI tar,只要我们容器支持OCI,基本上都是可以使用的
  • 同时导出可以使用--platform导出其它平台的(例如arm)
  • --all-platforms为导出所有平台
[root@ecs-65685 xyz]# ls
[root@ecs-65685 xyz]# ctr i ls -q
docker.io/library/nginx:alpine
[root@ecs-65685 xyz]# ctr i export --all-platforms nginx.tar docker.io/library/nginx:alpine
[root@ecs-65685 xyz]# ctr i export nginx_i4t.com.tar docker.io/library/nginx:alpine
[root@ecs-65685 xyz]# ls
nginx_i4t.com.tar nginx.tar
[root@ecs-65685 xyz]#
[root@ecs-65685 xyz]# ctr i rm docker.io/library/nginx:alpine
docker.io/library/nginx:alpine
[root@ecs-65685 xyz]# ctr i import nginx.tar
unpacking docker.io/library/nginx:alpine (sha256:b87c350e6c69e0dc7069093dcda226c4430f3836682af4f649f2af9e9b5f1c74)...done
[root@ecs-65685 xyz]# ctr i ls -q
docker.io/library/nginx:alpine

二、Containerd 容器操作

1 基本参数

[root@ecs-65685 ~]# ctr c create -h
NAME:
ctr containers create - create container USAGE:
ctr containers create [command options] [flags] Image|RootFS CONTAINER [COMMAND] [ARG...] OPTIONS:
--snapshotter value snapshotter name. Empty value stands for the default value. [$CONTAINERD_SNAPSHOTTER]
--snapshotter-label value labels added to the new snapshot for this container.
--config value, -c value path to the runtime-specific spec config file
--cwd value specify the working directory of the process
--env value specify additional container environment variables (e.g. FOO=bar)
--env-file value specify additional container environment variables in a file(e.g. FOO=bar, one per line)
--label value specify additional labels (e.g. foo=bar)
--mount value specify additional container mount (e.g. type=bind,src=/tmp,dst=/host,options=rbind:ro)
--net-host enable host networking for the container
--privileged run privileged container
--read-only set the containers filesystem as readonly
--runtime value runtime name (default: "io.containerd.runc.v2")
--runtime-config-path value optional runtime config path
--tty, -t allocate a TTY for the container
--with-ns value specify existing Linux namespaces to join at container runtime (format '<nstype>:<path>')
--pid-file value file path to write the task's pid
--gpus value add gpus to the container
--allow-new-privs turn off OCI spec's NoNewPrivileges feature flag
--memory-limit value memory limit (in bytes) for the container (default: 0)
--device value file path to a device to add to the container; or a path to a directory tree of devices to add to the container
--cap-add value add Linux capabilities (Set capabilities with 'CAP_' prefix)
--cap-drop value drop Linux capabilities (Set capabilities with 'CAP_' prefix)
--seccomp enable the default seccomp profile
--seccomp-profile value file path to custom seccomp profile. seccomp must be set to true, before using seccomp-profile
--apparmor-default-profile value enable AppArmor with the default profile with the specified name, e.g. "cri-containerd.apparmor.d"
--apparmor-profile value enable AppArmor with an existing custom profile
--rdt-class value name of the RDT class to associate the container with. Specifies a Class of Service (CLOS) for cache and memory bandwidth management.
--rootfs use custom rootfs that is not managed by containerd snapshotter
--no-pivot disable use of pivot-root (linux only)
--cpu-quota value Limit CPU CFS quota (default: -1)
--cpu-period value Limit CPU CFS period (default: 0)
--rootfs-propagation value set the propagation of the container rootfs

2 创建一个nginx容器

  • -n 指定命名空间
  • c 是简写 containers, c, container   manage containers
  • create 创建容器
  • --net-host 使用宿主机网络
  • docker.io/xx/xxx:xxx 镜像地址
  • nginx 容器名称
ctr -n xyz c create --net-host docker.io/library/nginx:alpine nginx

3 查看容器列表

[root@ecs-65685 ~]# ctr -n xyz c ls
CONTAINER IMAGE RUNTIME
nginx docker.io/library/nginx:alpine io.containerd.runc.v2
nginx1 docker.io/library/nginx:alpine io.containerd.runc.v2

4 只获取容器名称

[root@ecs-65685 ~]# ctr -n xyz c ls -q
nginx
nginx1

5 通过info参数查看容器的相关信息(类似于 docker inspect 功能)

ctr -n xyz c info nginx|less

6 删除容器

[root@ecs-65685 ~]# ctr -n xyz c ls -q
nginx
nginx1
[root@ecs-65685 ~]# ctr -n xyz container rm nginx1
[root@ecs-65685 ~]# ctr -n xyz c ls -q
nginx

除了使用 rm 子命令之外也可以使用 delete 或者 del 删除容器。

三、报错

ctr export导出或者import导入提示:ctr: content digest sha256:xxxxx: not found。

[root@ecs-65685 ~]# ctr image export --all-platforms nginx.tar docker.io/library/nginx:alpine
ctr: content digest sha256:36f21d30317cff60a6ab8328cca93dbe554020ba0320c78e964040512d0f27a0: not found

2 现象:

  • 直接导入某个镜像可能会出现类似于 ctr: content digest sha256:xxxxx: not found

解决办法:

  • 删除下载好的镜像
  • 拉取镜像、导出镜像时,都加上--all-platforms 时
  • 再次import和export,不需要添加--all-platforms

四、Containerd-1.6.5 命名空间和task使用

https://www.cnblogs.com/huaxiayuyi/p/16790210.html

Containerd-1.6.5 镜像容器操作的更多相关文章

  1. Docker:镜像操作和容器操作

    镜像操作 列出镜像: $ sudo docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE hello-world latest 0a6b ...

  2. 二、docker 镜像容器常用操作(让我们用docker 溜得飞起)

    前言 上篇讲了我们如何安装docker,现在该我们一展拳脚的时候了.接下来让我们一起学习一下docker常见的操作,让我们能够会使用 docker. 基本概念 在讲使用之前,还是先将一下docker ...

  3. docker学习笔记2--对镜像/容器的命令操作

    Docker启动一个Centos镜像 我们下载完成一个Centos镜像之后,开始启动 docker run -d -i -t <imageID> /bin/bash 这样就能启动一个一直停 ...

  4. 关于 Docker 镜像的操作,看完这篇就够啦 !(下)

    紧接着上篇<关于 Docker 镜像的操作,看完这篇就够啦 !(上)>,奉上下篇 !!! 镜像作为 Docker 三大核心概念中最重要的一个关键词,它有很多操作,是您想学习容器技术不得不掌 ...

  5. 004-docker命令-容器生命周期管理、容器操作

    1.容器生命周期管理 docker run :创建一个新的容器并运行一个命令 语法:docker run [OPTIONS] IMAGE [COMMAND] [ARG...] OPTIONS说明: - ...

  6. Docker镜像文件操作

    1什么是Docker镜像 Docker镜像是由文件系统叠加而成(是一种文件的存储形式).最底端是一个文件引导系统,即bootfs,这很像典型的Linux/Unix的引导文件系统.Docker用户几乎永 ...

  7. docker 容器操作( 以 tomcat 为例 )

    一.容器操作 一个镜像可以启动多个容器.比如一个 tomcat 镜像,可以启动多个tomcat 容器,启动后的这些 tomcat 都是各自独立的 二.步骤 1.搜索镜像 [root@localhost ...

  8. Minikube之Win10单机部署Kubernetes(k8s)自动化容器操作的开源平台

    Minikube之Win10单机部署 Kubernetes(k8s)是自动化容器操作的开源平台,基于这个平台,你可以进行容器部署,资源调度和集群扩容等操作.如果你曾经用过Docker部署容器,那么可以 ...

  9. Docker 镜像/容器操作命令

    一.镜像操作   1.拉取镜像 # docker pull tomcat # docker pull tomcat:8.0.21-jre8 # docker pull 192.168.220.150: ...

随机推荐

  1. 哈希-hash

    一. 概念 1.引例 有线性表(1,75,324,43,1353,90,46,-  ) 目的:查找值为90的元素 常见做法: 1.通过一维数组进行遍历查找 (依次比较)( O(n) ) 2.如果关键字 ...

  2. TensorFlow自定义训练函数

    本文记录了在TensorFlow框架中自定义训练函数的模板并简述了使用自定义训练函数的优势与劣势. 首先需要说明的是,本文中所记录的训练函数模板参考自https://stackoverflow.com ...

  3. 开源一个自动整理B站UWP客户端软件进行批量下载的视频文件的小工具BiliVideosReoganizeHelper​

    ​ 大家都知道B站是一个很受欢迎的视频学习网站,上面有很多无私的up主上传了大量优秀的教学视频,在此向B站致敬,向广大UP主致敬. 有时,我们需要下载收藏一些视频,以防止以后找不到了.那么我们可以用B ...

  4. Java基础 | Stream流原理与用法总结

    Stream简化元素计算: 一.接口设计 从Java1.8开始提出了Stream流的概念,侧重对于源数据计算能力的封装,并且支持序列与并行两种操作方式:依旧先看核心接口的设计: BaseStream: ...

  5. Apache DolphinScheduler ASF 孵化器毕业一周年,汇报来了!

    不知不觉,Apache DolphinScheduler 已经从 Apache 软件基金会(以下简称 ASF)孵化器毕业一年啦! 北京时间 2021 年 4 月 9 日,ASF 官方宣布 Apache ...

  6. 一个非常简单用.NET操作RabbitMQ的方法

    RabbitMQ作为一款主流的消息队列工具早已广受欢迎.相比于其它的MQ工具,RabbitMQ支持的语言更多.功能更完善. 本文提供一种市面上最/极简单的使用RabbitMQ的方式(支持.NET/.N ...

  7. Canvas 笔记目录

    Canvas 基础笔记 初次认识 Canvas Canvas 线性图形(一):路径 Canvas 线性图形(二):圆形 Canvas 线性图形(三):曲线 Canvas 线性图形(四):矩形 Canv ...

  8. ipv6临时地址

    关闭ipv6临时地址 win+r输入cmd进入后输入代码 netsh interface ipv6 setprivacy state=disable 控制面板中找到网卡禁用后在启用 win+r输入cm ...

  9. manim

    from manim import * #导入manim命名空间 #这是一个最基本的manim结构,类名叫做BaseFrame,传入一个场景Scene,并且包含一个construct方法,传入self ...

  10. ak日记 831 dxm

    import sys from math import inf line = sys.stdin.readline().strip() vs = list(map(int, line.split()) ...