Updated on 2024-01-26 GMT+08:00

Container Engine

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 1.23 and earlier versions):

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

  • Docker (community solution for Kubernetes 1.24 and later versions):

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

Command

crictl

docker

Kubernetes CRI

Native support

Support through dockershim or cri-dockerd

Pod startup delay

Low

High

kubelet CPU/memory usage

Low

High

Runtime's CPU/memory usage

Low

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

No.

Docker Command

containerd Command

Remarks

1

docker images [Option] [Image name[:Tag]]

crictl images [Option] [Image name[:Tag]]

List local images.

2

docker pull [Option] Image name[:Tag|@DIGEST]

crictl pull [Option] Image name[:Tag|@DIGEST]

Pull images.

3

docker push

None

Pushing images.

4

docker rmi [Option] Image...

crictl rmi [Option] Image ID...

Delete a local image.

5

docker inspect Image ID

crictl inspecti Image ID

Check images.

Table 3 Container-related commands

No.

Docker Command

containerd Command

Remarks

1

docker ps [Option]

crictl ps [Option]

List containers.

2

docker create [Option]

crictl create [Option]

Create a container.

3

docker start [Option] Container ID...

crictl start [Option] Container ID...

Start a container.

4

docker stop [Option] Container ID...

crictl stop [Option] Container ID...

Stop a container.

5

docker rm [Option] Container ID...

crictl rm [Option] Container ID...

Delete a container.

6

docker attach [Option] Container ID

crictl attach [Option] Container ID

Connect to a container.

7

docker exec [Option] Container ID Startup command [Parameter...]

crictl exec [Option] Container ID Startup command [Parameter...]

Access the container.

8

docker inspect [Option] Container name|ID...

crictl inspect [Option] Container ID...

Query container details.

9

docker logs [Option] Container ID

crictl logs [Option] Container ID

View container logs.

10

docker stats [Option] Container ID...

crictl stats [Option] Container ID

Check the resource usage of the container.

11

docker update [Option] Container ID...

crictl update [Option] Container ID...

Update container resource limits.

Table 4 Pod-related commands

No.

Docker Command

containerd Command

Remarks

1

None

crictl pods [Option]

List pods.

2

None

crictl inspectp [Option] Pod ID...

View pod details.

3

None

crictl start [Option] Pod ID...

Start a pod.

4

None

crictl runp [Option] Pod ID...

Run a pod.

5

None

crictl stopp [Option] Pod ID...

Stop a pod.

6

None

crictl rmp [Option] Pod ID...

Delete a pod.

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 1.23 and earlier versions):

    kubelet --> docker shim (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.