Pages

Friday, May 7, 2021

Understanding Container Runtimes - ContainerD

Container Runtimes are softwares that facilitate the containers to run. The Implementation for Containers started some time back and led to many container runtimes having their own formats. This approach has proven to be difficult and users find it hard to adopt to new container runtimes or port to the newer ones from current ones.

OCI ( Open Container Initiative ) : Keeping the problem in mind, a bunch of tech giants came together and formed OCI. The job of this is to define standards for the container ecosystem that help users to work on different runtimes with simplicity since they follow a Standard OCI format.

As we already know we have 2 levels in container runtime: High level and low level. ContainerD is a high level runtime and RunC is a low level runtime.RunC is a lightweight, portable container runtime which provides full support for linux namespaces and all other security features.The security features include SeLinux, AppArmor, Seccomp and Cgroups. This is used for spawning and running containers according to OCI ( Open Container Initiative ).

RunC is a low level implementation of a container runtime and containerD is builds on top of that. This includes providing higher level features like image transfer, storage, container execution and supervision. It also includes network, storage attachments etc basically manages the complete life cycle of containers.

In this article we will see how to work with ContainerD,

Install ContainerD:

wget https://github.com/containerd/containerd/releases/download/v1.3.4/containerd-1.3.4.linux-amd64.tar.gz

Extract the Package 

tar xvf containerd-1.3.4.linux-amd64.tar.gz


Check the files in the extracted package

[root@ip-172-31-32-147 bin]# ll

total 127024

-rwxr-xr-x. 1 2000 2000 53258624 Apr 16 01:18 containerd

-rwxr-xr-x. 1 2000 2000  7172096 Apr 16 01:18 containerd-shim

-rwxr-xr-x. 1 2000 2000  8790016 Apr 16 01:18 containerd-shim-runc-v1

-rwxr-xr-x. 1 2000 2000  8798208 Apr 16 01:18 containerd-shim-runc-v2

-rwxr-xr-x. 1 2000 2000 25063104 Apr 16 01:18 containerd-stress

-rwxr-xr-x. 1 2000 2000 26987552 Apr 16 01:18 ctr


Run the ContainerD in background as,

./containerd &


Pull a Container Image

[root@ip-172-31-32-147 bin]# ./ctr image pull centos

ctr: failed to resolve reference "centos": object required

This would give you an error saying you missed an object, because Containerd requires you to specify the object like the command below: [root@ip-172-31-32-147 bin]# ./ctr image pull docker.io/library/hello-world:latest


Check the Existing Images

[root@ip-172-31-32-147 bin]# ./ctr image ls -q

docker.io/library/hello-world:latest


Create a Container with the Existing Image

[root@ip-172-31-32-147 bin]# ./ctr container create docker.io/library/hello-world:latest demo


List the Running Containers

[root@ip-172-31-32-147 bin]# ./ctr container list

CONTAINER IMAGE                                          RUNTIME              

demo       docker.io/library/hello-world:latest. io.containerd.runc.v2


Delete the Image

[root@ip-172-31-32-147 bin]# ./ctr image remove docker.io/library/hello-world:latest


The output is not redirected to the CLI by default. Unlike Docker, we need to use the full path with the object every time we use a container image. Also, the image needs to be pulled before being able to run a container. Hope this helps in Understanding the basics of using ContainerD. More to Come, Happy Learning

No comments :

Post a Comment