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
主要檢視其中的 STATUS
,complete
表示映象是完整可用的狀態。
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 匯入匯出
[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
1 每個頂級設定塊的命名都是plugin."io.containerd.xxx.xxx.xxx"
這種形式,其實每個頂級設定塊都代表一個外掛。
其中io.containerd.xxx.xxx
表示外掛型別,xxx
後面的xxx
表示 外掛ID。
通過命令ctr plugin ls
檢視到
[root@ecs-65685 ~]# ctr plugin ls
TYPE ID PLATFORMS STATUS
io.containerd.content.v1 content - ok
io.containerd.snapshotter.v1 aufs linux/amd64 skip
io.containerd.snapshotter.v1 btrfs linux/amd64 skip
io.containerd.snapshotter.v1 devmapper linux/amd64 error
io.containerd.snapshotter.v1 native linux/amd64 ok
...
2 containerd相比於docker,多了namespace概念,每個image和containe都會在各自的namespace
下可見。
[root@ecs-65685 ~]# ctr ns ls
NAME LABELS
default
moby
[root@ecs-65685 ~]# ctr ns
NAME:
ctr namespaces - manage namespaces
USAGE:
ctr namespaces command [command options] [arguments...]
COMMANDS:
create, c create a new namespace
list, ls list namespaces
remove, rm remove one or more namespaces
label set and clear labels for a namespace
OPTIONS:
--help, -h show help
3 預設空間
k8s會使用k8s.io
作為名稱空間,預設containerd會使用default
。
docker 其實也是預設呼叫的 containerd,事實上 docker 使用的 containerd 下面的名稱空間預設是 moby
。
4 檢視當前所有namespace
[root@ecs-65685 ~]# ctr ns ls
NAME LABELS
default
moby
5 建立containerd namespace,不指定namespace,預設就會使用default
。
[root@ecs-65685 ~]# ctr ns create xyz
[root@ecs-65685 ~]# ctr ns ls
NAME LABELS
default
moby
xyz
6 測試名稱空間
-n xyz 下載映象進行測試,在ctr -n 指定名稱空間即可。
名稱空間只如果不指定,預設是看不到,這點和k8s namespace作用相同。
[root@ecs-65685 ~]# ctr -n xyz i pull docker.io/library/nginx:alpine --all-platforms
...
[root@ecs-65685 ~]# ctr -n xyz i ls -q
docker.io/library/nginx:alpine
7 分別檢視映象名稱
[root@ecs-65685 ~]# ctr -n default image ls -q
docker.io/library/nginx:alpine
[root@ecs-65685 ~]# ctr -n xyz image ls -q
docker.io/library/nginx:alpine
docker.io/library/redis:alpine
8 刪除名稱空間
[root@ecs-65685 ~]# ctr ns delete [NameSpace]
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容器
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 現象:
解決辦法:
--all-platforms
https://www.cnblogs.com/huaxiayuyi/p/16790210.html