Nerdctl: Docker compatible containerd command line tool
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.
Table of contents
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).
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:
Below is a view of running the tool in a Windows environment.
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
.
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
Exactly as you would expect with the Docker command line, you can issue the nerdctl ps
command to view running containers.
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.