هر Pod در Kubernetes، هر docker run، هر serverless container — در نهایت به یک runtime میرسد که process را spawn، filesystem mount، و lifecycle را manage میکند.
سالها Docker face بود — اما Docker Engine یک monolith بزرگ بود: CLI + API + image build + swarm + …
containerd همان engine هسته است — جدا شده، ساده، embeddable:
An industry-standard container runtime with an emphasis on simplicity, robustness and portability.
یعنی daemon که کل lifecycle container را manage میکند: image transfer/storage، execution، snapshot، network attachment — بدون UX developer-facing.
Docker امروز containerd را embed میکند. Kubernetes از CRI plugin containerd استفاده میکند. GKE، EKS، AKS، Bottlerocket، Fargate — همه روی containerd یا fork آن.
پروژه ۲۸ فوریه ۲۰۱۹ CNCF Graduated شد — بعد از Kubernetes، Prometheus، Envoy. containerd 2.0 اکنون stable است.
مشکل runtime monolithic
Docker Engine (قدیم):
CLI → API Server → containerd → runc
+ build + swarm + volumes + networks + ...
Kubernetes فقط به CRI نیاز داشت — نه build، نه swarm| نیاز | Docker monolith | containerd |
|---|---|---|
| Kubernetes CRI | shim اضافه | native plugin |
| Embed در product | سنگین | ✅ designed for embed |
| Attack surface | بزرگ | minimal daemon |
| Windows + Linux | ✅ | ✅ |
| OCI compliance | ✅ | ✅ first-class |
| Direct dev UX | ✅ docker CLI | nerdctl / ctr |
containerd برای platform engineer و distro builder است — نه end-user مستقیم (هرچند nerdctl شبیه Docker CLI است).
containerd چیست؟
containerd یک daemon برای Linux و Windows است که:
- Image pull/push — OCI Distribution Spec
- Content store — layer deduplication (CAS)
- Snapshotter — filesystem layers (overlayfs، stargz، …)
- Container execution — via OCI runtime (runc)
- Supervision — shim process per container group
- CRI plugin — Kubernetes kubelet interface
- Events — lifecycle notifications
- Namespaces — multi-tenant isolation در یک daemon
Repo: github.com/containerd/containerd
Docs: containerd.io/docs
License: Apache 2.0
تاریخچه و CNCF
| تاریخ | رویداد |
|---|---|
| ۲۰۱۵ | استخراج از Docker به پروژه مستقل |
| ۲۰۱۷ | donate به CNCF |
| مارس ۲۰۱۹ | CRI plugin GA — built into release |
| فوریه ۲۰۱۹ | CNCF Graduated |
| ۲۰۱۹ | CloudEvents v1.0 — unrelated but same era |
| ۲۰۲۴+ | containerd 2.x — API و plugin model بهبود |
Docker Inc. containerd را ساخت تا runtime را از developer tool جدا کند — Kubernetes SIG-Node همراستا شد.
معماری
نمای کلی
┌─────────────────────────────────────────────────────────┐
│ containerd daemon │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Content │ │Snapshotter│ │ Metadata │ │ Events │ │
│ │ Store │ │ overlayfs │ │ DB │ │ Bus │ │
│ └────┬─────┘ └────┬─────┘ └────┬─────┘ └──────────┘ │
│ │ │ │ │
│ ┌────┴────────────┴────────────┴─────────────────┐ │
│ │ gRPC API (unix socket) │ │
│ └────┬────────────┬────────────┬─────────────────┘ │
│ │ │ │ │
│ ┌────▼────┐ ┌────▼────┐ ┌────▼────┐ │
│ │ CRI │ │ ctr │ │ nerdctl │ ← clients │
│ │ plugin │ │ │ │ │ │
│ └────┬────┘ └─────────┘ └─────────┘ │
└───────┼────────────────────────────────────────────────┘
│
▼
┌───────────────────┐ ┌──────────────┐
│ containerd-shim │────►│ runc │ (OCI runtime)
│ runc v2 │ │ (or kata, │
└───────────────────┘ │ gVisor) │
│ └──────────────┘
▼
container process(es)
│
▼
CNI (network namespace)Plugin model
containerd یک plugin graph است — همه چیز plugin:
| Plugin | کاربرد |
|---|---|
| content | blob storage — image layers |
| snapshotter | writable rootfs از layers |
| metadata | container/image metadata DB |
| runtime v2 | task service → shim |
| CRI | Kubernetes API translation |
| transfer | image import/export |
| events | pub/sub lifecycle |
Clients (CRI، ctr، nerdctl، Docker) همه از همان gRPC API استفاده میکنند — daemon تفاوت client را نمیبیند.
Kubernetes: CRI Plugin
CRI (Container Runtime Interface) — API بین kubelet و runtime.
containerd از v1.1 CRI plugin را built-in و enabled by default دارد.
Flow: Pod با یک container
1. Kubelet → CRI RunPodSandbox
2. CRI → CNI: create pod network namespace
3. CRI → containerd: create pause container (sandbox)
4. Kubelet → CRI PullImage
5. CRI → containerd: pull OCI image (if missing)
6. Kubelet → CRI CreateContainer + StartContainer
7. CRI → containerd: create app container in pod cgroups/namespace
8. containerd-shim → runc → process runningPause container (registry.k8s.io/pause) — pod sandbox holder؛ app containers در namespace آن share میکنند.
Namespace: k8s.io
CRI همه objectها را در namespace k8s.io میسازد — جدا از ctr default namespace.
# لیست containerهای Kubernetes-managed
ctr -n k8s.io containers listOCI Standards
containerd OCI-native است:
| Spec | نقش |
|---|---|
| OCI Image Spec | image manifest، layers، config |
| OCI Runtime Spec | config.json — process، mounts، namespaces |
| OCI Distribution Spec | registry push/pull |
Runtime default: runc — reference OCI runtime. جایگزین: Kata Containers، gVisor، youki.
Snapshotters
Snapshotter writable rootfs از immutable layers میسازد:
| Snapshotter | توضیح |
|---|---|
| overlayfs | default — مثل Docker overlay2 |
| stargz | lazy pull — start قبل از full download |
| devmapper | block-device thin provisioning |
| btrfs / zfs | copy-on-write native |
| native | بدون overlay — testing |
config.toml:
[plugins."io.containerd.grpc.v1.cri".containerd]
snapshotter = "overlayfs"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
runtime_type = "io.containerd.runc.v2"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = trueRuntimeClass میتواند snapshotter یا runtime per-Pod تعیین کند — مثلاً stargz برای image بزرگ.
Runtime v2 و Shim
Runtime v2 — boundary بین containerd و process supervision:
containerd → Task Service → containerd-shim-runc-v2 → runc → container- Shim — parent process container؛ containerd میتواند restart شود بدون kill container
- runc v2 —
io.containerd.runc.v2— standard Linux path - Kata —
io.containerd.kata.v2— VM isolation
CLI Tools
| Tool | مخاطب | کاربرد |
|---|---|---|
| ctr | operator/debug | low-level containerd CLI |
| crictl | Kubernetes | CRI-compatible debug (pods، images) |
| nerdctl | developer | Docker-compatible CLI روی containerd |
ctr — low-level
# pull image
ctr images pull docker.io/library/nginx:alpine
# run container
ctr run --rm docker.io/library/nginx:alpine nginx-test
# list (default namespace)
ctr containers list
ctr -n k8s.io containers listcrictl — Kubernetes debug
# pods on node
crictl pods
crictl ps
crictl images
crictl logs <container-id>
crictl exec -it <container-id> sh
# pull via kubelet config
crictl pull nginx:alpinenerdctl — Docker-like UX
# شبیه docker
nerdctl run -d --name web nginx:alpine
nerdctl ps
nerdctl build -t myapp .
nerdctl compose upnerdctl — rootless، buildkit، compose — جایگزین Docker CLI روی containerd خالص.
نصب
Linux (systemd)
# Ubuntu/Debian — often pre-installed with Docker/K8s
sudo apt-get update
sudo apt-get install containerd
# یا binary از GitHub releases
wget https://github.com/containerd/containerd/releases/download/v2.0.4/containerd-2.0.4-linux-amd64.tar.gz
sudo tar Cxzvf /usr/local containerd-2.0.4-linux-amd64.tar.gz
# systemd unit
sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo systemctl enable --now containerdKubernetes با kubeadm
# containerd pre-installed — configure for systemd cgroup
containerd config default | tee /etc/containerd/config.toml
# set SystemdCgroup = true under runc.options
sudo systemctl restart containerd
kubeadm init --cri-socket unix:///run/containerd/containerd.sockWindows
containerd daemon روی Windows — hcsshim برای Windows containers.
config.toml Essentials
version = 3
[plugins."io.containerd.grpc.v1.cri"]
sandbox_image = "registry.k8s.io/pause:3.10"
[plugins."io.containerd.grpc.v1.cri".containerd]
snapshotter = "overlayfs"
default_runtime_name = "runc"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
runtime_type = "io.containerd.runc.v2"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
[plugins."io.containerd.grpc.v1.cri".registry]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint = ["https://mirror.example.com"]| Setting | چرا |
|---|---|
| SystemdCgroup = true | kubelet با systemd driver — الزامی روی modern K8s |
| sandbox_image | pause container version |
| registry.mirrors | pull از mirror داخلی |
| snapshotter | overlayfs default؛ stargz برای lazy pull |
containerd vs Docker vs CRI-O vs Podman
| containerd | Docker (Moby) | CRI-O | Podman | |
|---|---|---|---|---|
| Primary use | embed / K8s CRI | dev CLI + engine | K8s CRI only | rootless dev |
| K8s CRI | ✅ native | via cri-dockerd | ✅ native | ❌ (CRI-O separate) |
| Dev CLI | nerdctl | docker | ❌ | podman |
| Build images | nerdctl+buildkit | ✅ built-in | ❌ | ✅ buildah |
| Rootless | nerdctl | rootless mode | ❌ | ✅ default |
| Daemon | ✅ | ✅ | ✅ | optional (无daemon) |
| Windows | ✅ | ✅ | ❌ Linux only | ✅ |
Docker = containerd + dockerd + CLI + buildkit wrapper.
CRI-O — فقط CRI، سبکتر از containerd برای K8s-only node — Red Hat/OpenShift path.
Podman — daemonless، rootless-first — dev workstation.
containerd — industry standard embed — GKE/EKS/AKS node OS.
Adopters
از containerd.io:
| Adopter | نقش |
|---|---|
| Google GKE | node runtime |
| AWS EKS / Bottlerocket | container OS |
| Azure AKS | node runtime |
| AWS Fargate | serverless containers |
| Alibaba PouchContainer | fork/extend |
| Kata Containers | VM runtime via shim |
| Firecracker | microVM integration |
| LinuxKit | minimal OS |
| Docker | underlying runtime |
Features پیشرفته
Checkpoint / Restore
با CRIU — freeze container state و migrate:
# experimental — Linux
ctr tasks checkpoint --image-path /tmp/checkpoint web
ctr tasks restore web /tmp/checkpointUse case: live migration، debug، fast restart.
Live Restore
containerd restart بدون kill running containers — shim process نگه میدارد.
Events
ctr events
# subscribe lifecycle: create, start, exit, deleteIntegration با monitoring و CloudEvents downstream.
Transfer Plugin
OCI image import/export بدون registry — air-gapped environments.
containerd 2.0
- API cleanup
- plugin registration بهبود
- performance و stability
- docs:
docs/containerd-2.0.md
Security
- Minimal attack surface — no build، no swarm در core
- Rootless via nerdctl
- AppArmor/SELinux — OCI spec labels
- Seccomp — default profiles
- Audit — published security audits
- CVE process — containerd/project
| Layer | hardening |
|---|---|
| Runtime | Kata برای untrusted workload |
| Network | Cilium policy |
| Image | signed images، digest pin |
| Host | Bottlerocket — immutable OS + containerd |
Troubleshooting
# daemon status
systemctl status containerd
journalctl -u containerd -f
# CRI debug
crictl info
crictl pods --name my-pod -n production
# containerd low-level
ctr plugins ls
ctr -n k8s.io containers list
ctr -n k8s.io tasks list
# common: ImagePullBackOff
crictl pull <image> # test pull manually
crictl images | grep <name>| علامت | علت | fix |
|---|---|---|
| Pod SandboxChanged | pause container restart | check cgroup driver |
| SystemdCgroup mismatch | config.toml | SystemdCgroup = true |
| CNI error | network plugin | CNI config in /etc/cni/net.d |
| shim not found | runtime not installed | install runc، restart |
| disk full | image layers | crictl rmi --prune |
| namespace confusion | wrong ctr namespace | use -n k8s.io |
containerd در stack P30Light
Host OS (Bottlerocket / Ubuntu)
│
▼
containerd daemon
├── CRI → kubelet → Pods
├── [Cilium](/blog/cilium-ebpf-kubernetes-networking/) CNI
├── [Kata](/blog/kata-containers-secure-container-runtime/) RuntimeClass (optional)
└── nerdctl / crictl (ops)
│
▼
[Cloud Native Buildpacks](/blog/cloud-native-buildpacks-cnb-guide/) → OCI image → containerd pullImage build با CNB → push registry → containerd pull → run — pipeline استاندارد.
چه زمانی containerd؟
✅ مناسب
- Kubernetes node — default runtime (با kubeadm، k3s، RKE2)
- Cloud managed K8s — GKE/EKS/AKS underlying
- Embed در product — custom platform
- Minimal container OS — Bottlerocket، Flatcar
- Docker replacement در production — nerdctl + containerd
- Multi-runtime — runc + Kata via RuntimeClass
❌ کمتر مناسب
| وضعیت | جایگزین |
|---|---|
| Developer laptop «فقط docker compose» | Docker Desktop / Podman |
| OpenShift strict | CRI-O (CRIO) |
| Daemonless rootless dev | Podman |
| VM orchestration | KubeVirt — layer بالاتر |
عملیات روزمره
# prune unused images (Kubernetes node)
crictl rmi --prune
# disk usage
ctr -n k8s.io content ls
du -sh /var/lib/containerd/
# after upgrade
systemctl restart containerd
# running containers survive via shim
# validate CRI
critest --runtime-endpoint=unix:///run/containerd/containerd.sockجمعبندی
| Docker monolith | containerd |
|---|---|
| همهکاره dev tool | focused runtime |
| embed سخت | designed to embed |
| CRI via shim | native CRI plugin |
| vendor-tied narrative | CNCF Graduated standard |
containerd موتور واقعی behind modern containers است — ساده، robust، portable. Kubernetes، Docker، Fargate، Bottlerocket — همه روی این daemon یا fork آن.
Platform engineer که node Kubernetes را میشناسد، containerd را باید بشناسد — از CRI flow تا snapshotter و crictl debug.
قدم بعدی
containerdروی Linux VM نصب —ctr run hello-worldconfig.toml—SystemdCgroup = trueبرای kubeadm- cluster با
--cri-socket unix:///run/containerd/containerd.sock crictl pods/crictl ps— debug Pod- nerdctl نصب — Docker-like workflow بدون dockerd
- RuntimeClass با Kata — secure workload test
منابع:
- containerd — Official Site
- Documentation
- CRI Architecture
- CRI Config
- Getting Started
- GitHub — containerd/containerd
- nerdctl
- crictl
- OCI Image Spec
منتشر شده در P30Light — بخش زیرساخت سرور و Cloud Native.