Updated on 2024-10-14 GMT+08:00

Container Engines

Introduction to Container Engines

Container engines, one of the most important components of Kubernetes, manage the lifecycle of images and containers. The kubelet interacts with a container runtime through the Container Runtime Interface (CRI).

CCE supports containerd and Docker. containerd is recommended for its shorter traces, fewer components, higher stability, and less consumption of node resources.

Table 1 Comparison between container engines

Item

containerd

Docker

Tracing

kubelet --> CRI plugin (in the containerd process) --> containerd

  • Docker (Kubernetes v1.23 and earlier versions):

    kubelet --> dockershim (in the kubelet process) --> docker --> containerd

  • Docker (community solution for Kubernetes v1.24 or later):

    kubelet --> cri-dockerd (kubelet uses CRI to connect to cri-dockerd) --> docker--> containerd

Command

crictl/ctr

docker

Kubernetes CRI

Native support

Support through dockershim or cri-dockerd

Pod delayed startup

Minor

High

kubelet CPU/memory usage

Minor

High

Runtime's CPU/memory usage

Minor

High

Common Commands of containerd and Docker

containerd does not support Docker APIs and Docker CLI, but you can run crictl commands to implement similar functions.

Table 2 Image-related commands

Operation

Docker Command

containerd Command

docker

crictl

ctr

List local images.

docker images

crictl images

ctr -n k8s.io i ls

Pull images.

docker pull

crictl pull

ctr -n k8s.io i pull

Push images.

docker push

None

ctr -n k8s.io i push

Delete a local image.

docker rmi

crictl rmi

ctr -n k8s.io i rm

Check images.

docker inspect

crictl inspecti

None

Table 3 Container-related commands

Operation

Docker Command

containerd Command

docker

crictl

ctr

List containers.

docker ps

crictl ps

ctr -n k8s.io c ls

Create a container.

docker create

crictl create

ctr -n k8s.io c create

Start a container.

docker start

crictl start

ctr -n k8s.io run

Stop a container.

docker stop

crictl stop

None

Delete a container.

docker rm

crictl rm

ctr -n k8s.io c del

Connect to a container.

docker attach

crictl attach

None

Access the container.

docker exec

crictl exec

None

Query container details.

docker inspect

crictl inspect

ctr -n k8s.io c info

View container logs.

docker logs

crictl logs

None

Check the resource usage of the container.

docker stats

crictl stats

None

Update container resource limits.

docker update

crictl update

None

Table 4 Pod-related commands

Operation

Docker Command

containerd Command

docker

crictl

ctr

List pods.

None

crictl pods

None

View pod details.

None

crictl inspectp

None

Start a pod.

None

crictl start

None

Run a pod.

None

crictl runp

None

Stop a pod.

None

crictl stopp

None

Delete a pod.

None

crictl rmp

None

Containers created and started by containerd are immediately deleted by kubelet. containerd does not support suspending, resuming, restarting, renaming, and waiting for containers, nor Docker image build, import, export, comparison, push, search, and labeling. containerd does not support file copy. You can log in to the image repository by modifying the configuration file of containerd.

Differences in Tracing

  • Docker (Kubernetes v1.23 and earlier versions):

    kubelet --> dockershim (in the kubelet process) --> docker --> containerd

  • Docker (community solution for Kubernetes v1.24 or later):

    kubelet --> cri-dockerd (kubelet uses CRI to connect to cri-dockerd) --> docker--> containerd

  • containerd:

    kubelet --> CRI plugin (in the containerd process) --> containerd

Although Docker has added functions such as swarm cluster, docker build, and Docker APIs, it also introduces bugs. Compared with containerd, Docker has one more layer of calling. Therefore, containerd is more resource-saving and secure.