containerd 像Docker一樣絲滑操作鏡像【轉】

containerd 像Docker一樣絲滑操作鏡像

  • • 我們知道 Docker CLI 工具提供了需要增強用戶體驗的功能,containerd 同樣也提供一個對應的 CLI 工具:ctr,不過 ctr 的功能沒有 docker 完善,但是關於鏡像和容器的基本功能都是有的。接下來我們就先簡單介紹下 ctr 的使用。

➜  ~ ctr
NAME:
   ctr -
        __
  _____/ /______
 / ___/ __/ ___/
/ /__/ /_/ /
\___/\__/_/

containerd CLI


USAGE:
   ctr [global options] command [command options] [arguments...]

VERSION:
   v1.5.5

DESCRIPTION:

ctr is an unsupported debug and administrative client for interacting
with the containerd daemon. Because it is unsupported, the commands,
options, and operations are not guaranteed to be backward compatible or
stable from release to release of the containerd project.

COMMANDS:
   plugins, plugin            provides information about containerd plugins
   version                    print the client and server versions
   containers, c, container   manage containers
   content                    manage content
   events, event              display containerd events
   images, image, i           manage images
   leases                     manage leases
   namespaces, namespace, ns  manage namespaces
   pprof                      provide golang pprof outputs for containerd
   run                        run a container
   snapshots, snapshot        manage snapshots
   tasks, t, task             manage tasks
   install                    install a new package
   oci                        OCI tools
   shim                       interact with a shim directly
   help, h                    Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --debug                      enable debug output in logs
   --address value, -a value    address for containerd's GRPC server (default: "/run/containerd/containerd.sock") [$CONTAINERD_ADDRESS]
   --timeout value              total timeout for ctr commands (default: 0s)
   --connect-timeout value      timeout for connecting to containerd (default: 0s)
   --namespace value, -n value  namespace to use with commands (default: "default") [$CONTAINERD_NAMESPACE]
   --help, -h                   show help
   --version, -v                print the version

鏡像操作

拉取鏡像

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

# ctr image pull docker.io/library/nginx:alpine
也可以使用 --platform 選項指定對應平臺的鏡像。當然對應的也有推送鏡像的命令 ctr image push,如果是私有鏡像則在推送的時候可以通過 --user 來自定義倉庫的用戶名和密碼。

列出本地鏡像

# ctr image ls

# ctr image ls -q

使用 -q(--quiet) 選項可以只打印鏡像名稱

檢測本地鏡像

ctr image check
REF                            TYPE                                                      DIGEST                                                                  STATUS         SIZE            UNPACKED
docker.io/library/nginx:alpine application/vnd.docker.distribution.manifest.list.v2+json sha256:bead42240255ae1485653a956ef41c9e458eb077fcb6dc664cbc3aa9701a05ce complete (7/7) 9.5 MiB/9.5 MiB true
# 主要查看其中的 STATUS,complete 表示鏡像是完整可用的狀態。

重新打標籤

  • • 同樣的我們也可以重新給指定的鏡像打一個 Tag:

# ctr image tag docker.io/library/nginx:alpine harbor.k8s.local/course/nginx:alpine
harbor.k8s.local/course/nginx:alpine
# ctr image ls -q
docker.io/library/nginx:alpine
harbor.k8s.local/course/nginx:alpine

刪除鏡像

# ctr image rm harbor.k8s.local/course/nginx:alpine
harbor.k8s.local/course/nginx:alpine
# ctr image ls -q
docker.io/library/nginx:alpine

加上 --sync 選項可以同步刪除鏡像和所有相關的資源。

將鏡像導出爲壓縮包

# ctr image export nginx.tar.gz docker.io/library/nginx:alpine

從壓縮包導入鏡像

ctr image import nginx.tar.gz

Containerd 像Docker一樣絲滑操作鏡像
https://mp.weixin.qq.com/s/fwwjeVUEY01ZZy6RlQELnA

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章