How to Deploy Containers with nerdctl

How many ways can you deploy a container? Shall we count them?

Seriously, we don’t have all day.

Really, there are more ways to deploy containers than I can count on my hands. For some, that might be a bit of an exaggeration. However, for those who like options, the idea that there are so many deployment methods is a huge plus.

For those who fall into this category, let me add one more method to your ever-growing stack of choices. Said method is via nerdctl.

How can you resist this name? You can’t, that’s the way it is.

The nerdctl command sits on top of containerd to allow containers to be deployed over this runtime. Why? Because containerd alone is not much help. In fact, you can’t deploy containers with containerd because it’s a runtime used in conjunction with other tools for this purpose.

Ergo, nerdctl.

Let’s first install containerd on an Ubuntu Server system and then add nerdctl over it. Then we provide our first container.

Why use nerdctl?

Besides the cool name, nerdctl offers features like:

  • Works similar to Docker
  • Supports Docker Compose
  • Supports rootless mode (without Slirp overhead)
  • Supports lazy pulling of images
  • Supports encrypted images
  • Supports P2P image distribution
  • Supports signing and verifying container images

requirements

To successfully install these tools, you need a running instance of Ubuntu Server 22.04 and a user with sudo privileges. Once you have those bits in place, it’s time to get busy.

install containerd

First you need to install containerd. Before doing anything, be sure to check the Containerd download page to ensure you’re downloading the latest version of the software. At this point in time that would be 1.6.8.

Login to your instance of Ubuntu and open a terminal window. In the terminal, issue the command:

Once the download is complete, unzip containerd in /usr/local with the command:

Brilliant!

Next we need to download the Runc command line tool with the command:

install runc with:

Next we need the Container Network Interface (CNI) which can be downloaded with:

Create a new directory for CNI with:

Unpack CNI into the new directory with:

We now need to configure containerd. Create a directory for the configuration with:

Generate the configuration file with:

Next we need to enable the SystemdCgroup with:

In order to manage the containerd service, we need to download a pre-configured systemd file with the command:

Reload the systemd daemon with:

Start and activate Containerd with:

Hooray! You are now ready for nerdctl

Install nerdctl

Before we can install nerdctl, we first need to add a few necessary dependencies with the command:

When the dependencies are done, download the nerdctl file with:

Extract the file to /usr/local/bin with the command:

You should be able to verify that nerdctl is up and running with the following command:

You should see this:

Now we need to configure the system to be able to serve rootless containers. Create a systemd file with:

In the new file, paste the following:

Save and close the file. To set up containerd for rootless, enter the command:

Install containerd-rootless-setuptool.sh

To run nerdctl without using sudo, run the following two commands:

We are now ready to rock our first container.

Deploying a container with nerdctl

Fortunately, deploying containers with nerdctl is very similar to Docker. For example, to deploy an NGINX container using Docker, the command is:

To do the same with nerdctl the command would be:

Congratulations, your container deployment just got a little more nerdy (and who doesn’t appreciate that?). If you’re in a situation where containerd is the engine of choice and you want a Docker-like deployment, you can’t go wrong with nerdctl.

groupCreated with Sketch.

Leave a Reply

Your email address will not be published. Required fields are marked *