Containers

Nerdctl: Docker compatible containerd command line tool

Explore the power of nerdctl, the Docker-compatible CLI for containerd, offering enhanced container management, security, and efficiency.

Nerdctl is a tool that works with containerd but also provides command line support for many docker cli commands. This makes it a great solultion and option when looking to replace Docker in many cases. For example, the simple docker command to list containers, docker ps, translates directly into nerdctl ps in nerdctl. Let’s look at more nerdctl commands to take note of.

What is Nerdctl?

Nerdctl is a command-line interface (CLI) that stands for nerd control and is designed to be a docker compatible cli for containerd, a widely-used open-source container runtime. It serves as a bridge between users and the functionalities of containerd, providing a familiar and intuitive interface that many developers have come to know through their experience with Docker.

Setting Up Nerdctl

To start using nerdctl on your system, you first need to install it along with the containerd runtime. The installation will depend on your host operating system, such as an Ubuntu server. It requires sudo privileges.

You can download the tool from the Github repo releases page here: Releases ยท containerd/nerdctl (github.com).

Download nerdctl executable from the Github repository
Download nerdctl executable from the Github repository
wget https://github.com/containerd/nerdctl/releases/download/v1.4.0/nerdctl-1.4.0-linux-amd64.tar.gz

This will pull down the archive package. You will need to unzip the file using:

tar -xzf nerdctl-1.4.0-linux-amd64.tar.gz

After unpacking the downloaded file, you can add nerdctl to your local executable directory using:

sudo mv ./nerdctl /usr/local/bin

You should then be able to execute nerdctl:

Nerdctl tool running in Ubuntu Server
Nerdctl tool running in Ubuntu Server

Below is a view of running the tool in a Windows environment.

Nerdctl command line tool running in Windows
Nerdctl command line tool running in Windows

Nerdctl Vs. Docker Desktop and Rancher Desktop

Docker Desktop, Nerdctl, and Rancher Desktop are all really good tools when looking for a container tool for your desktop. They all support docker compose files which means you can run compose code like you would for docker containers. A docker compose file can be executed using nerdctl compose up, very similar to what you would do with docker compose up.

Rancher Desktop includes nerdctl to interact with containerd
ancher Desktop includes nerdctl to interact with containerd

Working with Images and Containers

Working with container images is another aspect where nerdctl provides a really great tool. Nerdctl commands include things like the following to pull an image from a container registry:

nerdctl pull nginx

You can also use the following to run an nginx container with port forwarding, mirroring docker cli commands:

nerdctl run -d -p 8080:80 nginx 
Pulling a container image and running the image with nerdctl 1
Pulling a container image and running the image with nerdctl

Exactly as you would expect with the Docker command line, you can issue the nerdctl ps command to view running containers.

Getting containers with nerdctl
Getting containers with nerdctl

Rootless Mode and Lazy Pulling

Rootless mode is a feature that allows you to run containers without sudo privileges, and lazy pulling, which means you pull only the parts of the container image that are necessary when you are running containers. are unique features to nerdctl. For example, you can use rootless mode:

 nerdctl --rootless run

Coming from Docker

Coming from Docker to nerdctl is something you can do fairly easily since the commands and syntax are so similar. As shown above, the command nerdctl run -d -p 8080:80 nginx, used to deploy an nginx container, is quite similar to the corresponding Docker command.

Wrapping up

Nerdctl is a tool that will be familiar to most even if they have never used it. This is due to being basically the same syntax as Docker cli commands. Using nerdctl is something you will feel familiar using with tools like Rancher Desktop. I like the fact too that you can use Docker Compose code with nerdctl. This means you won’t have to refactor your code to work with nerdctl coming from Docker.

Subscribe to VirtualizationHowto via Email ๐Ÿ””

Enter your email address to subscribe to this blog and receive notifications of new posts by email.



Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com, and a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

Related Articles

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.