Кратко: команды containerd (crctl/ctr)

Как давно я сюда не писал. Начну с публикации своих «заметок» по работе.

Ниже кратко расписаны наиболее популярные команды ctr и crictl.

ctr

Это CLI который позволит вам управлять и создавать контейнеры в containerd

https://github.com/projectatomic/containerd/blob/master/docs/cli.md

get namespase

ctr namespace list

посмотреть запущенные контейнеры в определенном неймспейсе

ctr --namespace moby container list

Images

pulling images

ctr images pull docker.io/library/nginx:1.21
ctr images pull docker.io/kennethreitz/httpbin:latest
ctr images pull docker.io/kennethreitz/httpbin:latest
ctr images pull quay.io/quay/redis:latest

list local images

ctr images ls

import existing images

docker build -t my-app .
docker save -o my-app.tar my-app
ctr images import my-app.tar

mount images

mkdir /tmp/httpbin
ctr images mount docker.io/kennethreitz/httpbin:latest /tmp/httpbin

ls -l /tmp/httpbin/
total 80
drwxr-xr-x 2 root root 4096 Oct 18  2018 bin
drwxr-xr-x 2 root root 4096 Apr 24  2018 boot
drwxr-xr-x 4 root root 4096 Oct 18  2018 dev
drwxr-xr-x 1 root root 4096 Oct 24  2018 etc
drwxr-xr-x 2 root root 4096 Apr 24  2018 home
drwxr-xr-x 3 root root 4096 Oct 24  2018 httpbin
...

ctr images unmount /tmp/httpbin

remove images

ctr images remove docker.io/library/nginx:1.21

container

run a container

$ ctr run --rm -t docker.io/library/debian:latest cont1

list existing containers

$ ctr containers ls

example

$ ctr container create -t docker.io/library/nginx:latest nginx_1
$ ctr container ls
CONTAINER    IMAGE                              RUNTIME
nginx_1      docker.io/library/nginx:latest     io.containerd.runc.v2

$ ctr task ls
TASK    PID    STATUS        # Empty!

$ ctr task start -d nginx_1  # -d for --detach
$ ctr task list
TASK     PID      STATUS
nginx_1  10074    RUNNING

reconnect to the stdio streams

ctr task attach nginx_1

execute a task in an existing container

ctr task exec -t --exec-id bash_1 nginx_1 bash

stop/removing

Before removing a container, all its tasks must be stopped

ctr task kill -9 nginx_1

you can remove running tasks using the --force flag:

$ ctr task rm -f nginx_1

Finally, to remove the container, run:

$ ctr container rm nginx_1

crictl

crictl — эта утилита была создана для проверке и отладке среды выполнения контейнеров и приложений в kuberneties.

attach: Attach to a running container
create: Create a new container
exec: Run a command in a running container
version: Display runtime version information
images, image, img: List images
inspect: Display the status of one or more containers
inspecti: Return the status of one or more images
imagefsinfo: Return image filesystem info
inspectp: Display the status of one or more pods
logs: Fetch the logs of a container
port-forward: Forward local port to a pod
ps: List containers
pull: Pull an image from a registry
run: Run a new container inside a sandbox
runp: Run a new pod
rm: Remove one or more containers
rmi: Remove one or more images
rmp: Remove one or more pods
pods: List pods
start: Start one or more created containers
info: Display information of the container runtime
stop: Stop one or more running containers
stopp: Stop one or more running pods
update: Update one or more running containers
config: Get and set crictl client configuration options
stats: List container(s) resource usage statistics

Немного материалов из интернетов: