|
| 1 | +--- |
| 2 | +title: Nerdctl |
| 3 | +author: Jason Andrews |
| 4 | + |
| 5 | +draft: true |
| 6 | + |
| 7 | +minutes_to_complete: 10 |
| 8 | + |
| 9 | +official_docs: https://github.com/containerd/nerdctl/blob/main/docs/command-reference.md |
| 10 | + |
| 11 | +additional_search_terms: |
| 12 | +- container |
| 13 | +- containerd |
| 14 | +- docker |
| 15 | +- Linux |
| 16 | + |
| 17 | +test_images: |
| 18 | +- ubuntu:latest |
| 19 | +test_maintenance: false |
| 20 | + |
| 21 | +tool_install: true |
| 22 | +layout: installtoolsall |
| 23 | +multi_install: false |
| 24 | +multitool_install_part: false |
| 25 | +weight: 1 |
| 26 | +--- |
| 27 | + |
| 28 | +[Nerdctl](https://github.com/containerd/nerdctl) is an open-source command-line interface (CLI) designed to be compatible with the Docker CLI, but specifically for interacting with [containerd](https://containerd.io/). It provides a familiar user experience for developers who are familiar with Docker, while leveraging the capabilities of containerd as the underlying container runtime. |
| 29 | + |
| 30 | +Using containerd and nerdctl provides similar functionality to Docker but with a smaller memory footprint, making it ideal for IoT and edge solutions, especially on Arm devices that balance energy efficiency and performance. |
| 31 | + |
| 32 | +Nerdctl also supports running containers in rootless mode, which helps enhance security by not requiring elevated privileges. Rootless mode is not covered below but you can refer to the [documentation](https://rootlesscontaine.rs/getting-started/containerd/) for information about how to run `containerd-rootless-setuptool.sh install`. |
| 33 | + |
| 34 | +This guide explains how to install and use containerd and nerdctl on Arm Linux and run with `sudo` |
| 35 | + |
| 36 | +## Before you begin |
| 37 | + |
| 38 | +This guide assumes you are using a Debian-based Arm Linux distribution, including Ubuntu and Raspberry Pi OS. You can use a local Arm Linux computer or an Arm instance in the cloud. |
| 39 | + |
| 40 | +Confirm you are using an Arm machine by running: |
| 41 | + |
| 42 | +```bash |
| 43 | +uname -m |
| 44 | +``` |
| 45 | + |
| 46 | +The output should be: |
| 47 | + |
| 48 | +```output |
| 49 | +aarch64 |
| 50 | +``` |
| 51 | + |
| 52 | +Ensure `wget` and `tar` are installed. Most distributions will include them, but if not run: |
| 53 | + |
| 54 | +```bash |
| 55 | +sudo apt-get update |
| 56 | +sudo apt-get install -y wget tar |
| 57 | +``` |
| 58 | + |
| 59 | +## Install containerd |
| 60 | + |
| 61 | +Install the containerd runtime: |
| 62 | + |
| 63 | +```bash |
| 64 | +sudo apt-get install containerd -y |
| 65 | +``` |
| 66 | + |
| 67 | +Start and enable the containerd service: |
| 68 | + |
| 69 | +```bash |
| 70 | +sudo systemctl start containerd |
| 71 | +sudo systemctl enable containerd |
| 72 | +``` |
| 73 | + |
| 74 | +Confirm the service is running: |
| 75 | + |
| 76 | +```console |
| 77 | +systemctl status containerd.service |
| 78 | +``` |
| 79 | + |
| 80 | +When containerd is running, the output is similar to: |
| 81 | + |
| 82 | +```output |
| 83 | +● containerd.service - containerd container runtime |
| 84 | + Loaded: loaded (/usr/lib/systemd/system/containerd.service; enabled; preset: enabled) |
| 85 | + Active: active (running) since Tue 2025-04-22 20:12:03 UTC; 2min 20s ago |
| 86 | + Docs: https://containerd.io |
| 87 | + Main PID: 8428 (containerd) |
| 88 | + Tasks: 9 |
| 89 | + Memory: 13.0M (peak: 13.7M) |
| 90 | + CPU: 401ms |
| 91 | + CGroup: /system.slice/containerd.service |
| 92 | + └─8428 /usr/bin/containerd |
| 93 | +``` |
| 94 | + |
| 95 | +## Install nerdctl and CNI plugins |
| 96 | + |
| 97 | +Install nerdctl and the necessary CNI (Container Network Interface) plugins. |
| 98 | + |
| 99 | +```bash |
| 100 | +NERDCTL_VERSION=$(curl -s https://api.github.com/repos/containerd/nerdctl/releases/latest | grep tag_name | cut -d '"' -f 4 | sed 's/v//') |
| 101 | +wget https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-${NERDCTL_VERSION}-linux-arm64.tar.gz |
| 102 | +sudo tar -xzvf nerdctl-${NERDCTL_VERSION}-linux-arm64.tar.gz -C /usr/local/bin |
| 103 | +``` |
| 104 | + |
| 105 | +Install the CNI plugins: |
| 106 | + |
| 107 | +```bash |
| 108 | +CNI_VERSION=$(curl -s https://api.github.com/repos/containernetworking/plugins/releases/latest | grep tag_name | cut -d '"' -f 4 | sed 's/v//') |
| 109 | +wget https://github.com/containernetworking/plugins/releases/download/v${CNI_VERSION}/cni-plugins-linux-arm64-v${CNI_VERSION}.tgz |
| 110 | +sudo mkdir -p /opt/cni/bin |
| 111 | +sudo tar -xzvf cni-plugins-linux-arm64-v${CNI_VERSION}.tgz -C /opt/cni/bin |
| 112 | +``` |
| 113 | + |
| 114 | +Clean up the downloaded files: |
| 115 | + |
| 116 | +```bash |
| 117 | +rm nerdctl-${NERDCTL_VERSION}-linux-arm64.tar.gz cni-plugins-linux-arm64-v${CNI_VERSION}.tgz |
| 118 | +``` |
| 119 | + |
| 120 | +{{% notice Note %}} |
| 121 | +The commands above attempt to fetch the latest versions automatically. If required, you can replace `${NERDCTL_VERSION}` and `${CNI_VERSION}` with specific versions. |
| 122 | +{{% /notice %}} |
| 123 | + |
| 124 | +## Install BuildKit |
| 125 | + |
| 126 | +If you want to build container images with nerdctl, you need to install [BuildKit](https://github.com/moby/buildkit). |
| 127 | + |
| 128 | +If you only need to run container images you can skip this step. |
| 129 | + |
| 130 | +```bash |
| 131 | +BUILDKIT_VERSION=$(curl -s https://api.github.com/repos/moby/buildkit/releases/latest | grep tag_name | cut -d '"' -f 4 | sed 's/v//') |
| 132 | +wget https://github.com/moby/buildkit/releases/download/v${BUILDKIT_VERSION}/buildkit-v${BUILDKIT_VERSION}.linux-arm64.tar.gz |
| 133 | +sudo tar -xzvf buildkit-v${BUILDKIT_VERSION}.linux-arm64.tar.gz -C /usr |
| 134 | +rm buildkit-v${BUILDKIT_VERSION}.linux-arm64.tar.gz |
| 135 | +``` |
| 136 | + |
| 137 | +Create a systemd service for BuildKit: |
| 138 | + |
| 139 | +```bash |
| 140 | +sudo tee /etc/systemd/system/buildkit.service > /dev/null << EOF |
| 141 | +[Unit] |
| 142 | +Description=BuildKit |
| 143 | +Documentation=https://github.com/moby/buildkit |
| 144 | +
|
| 145 | +[Service] |
| 146 | +ExecStart=/usr/bin/buildkitd --oci-worker=false --containerd-worker=true |
| 147 | +
|
| 148 | +[Install] |
| 149 | +WantedBy=multi-user.target |
| 150 | +EOF |
| 151 | +``` |
| 152 | + |
| 153 | +Start and enable the BuildKit service: |
| 154 | + |
| 155 | +```bash |
| 156 | +sudo systemctl daemon-reload |
| 157 | +sudo systemctl start buildkit |
| 158 | +sudo systemctl enable buildkit |
| 159 | +``` |
| 160 | + |
| 161 | +Verify BuildKit is running: |
| 162 | + |
| 163 | +```console |
| 164 | +sudo systemctl status buildkit |
| 165 | +``` |
| 166 | + |
| 167 | +When running, the output is similar to: |
| 168 | + |
| 169 | +```output |
| 170 | +ubuntu@m1u:~$ sudo systemctl status buildkit |
| 171 | +● buildkit.service - BuildKit |
| 172 | + Loaded: loaded (/etc/systemd/system/buildkit.service; enabled; preset: enabled) |
| 173 | + Active: active (running) since Tue 2025-04-22 22:55:39 CDT; 18min ago |
| 174 | + Docs: https://github.com/moby/buildkit |
| 175 | + Main PID: 22280 (buildkitd) |
| 176 | + Tasks: 10 (limit: 4598) |
| 177 | + Memory: 14.6M (peak: 42.0M) |
| 178 | + CPU: 1.144s |
| 179 | + CGroup: /system.slice/buildkit.service |
| 180 | + └─22280 /usr/bin/buildkitd --oci-worker=false --containerd-worker=true |
| 181 | +``` |
| 182 | + |
| 183 | +Check that buildctl can communicate with the daemon: |
| 184 | + |
| 185 | +```console |
| 186 | +sudo buildctl debug workers |
| 187 | +``` |
| 188 | + |
| 189 | +If BuildKit is properly installed, you should see output similar to: |
| 190 | + |
| 191 | +```output |
| 192 | +ID PLATFORMS |
| 193 | +jz1h9gb0xq39ob6868cr3ev6r linux/arm64 |
| 194 | +``` |
| 195 | + |
| 196 | +## Verify the installation |
| 197 | + |
| 198 | +You can check the nerdctl version: |
| 199 | + |
| 200 | +```console |
| 201 | +sudo nerdctl version |
| 202 | +``` |
| 203 | + |
| 204 | +Test your installation by running a simple container that prints the processor architecture: |
| 205 | + |
| 206 | +```console |
| 207 | +sudo nerdctl run --name uname armswdev/uname |
| 208 | +``` |
| 209 | + |
| 210 | +Wait a few seconds for the container to start. The architecture is printed: |
| 211 | + |
| 212 | +```output |
| 213 | +Architecture is aarch64 |
| 214 | +``` |
| 215 | + |
| 216 | +Clean up the test container: |
| 217 | + |
| 218 | +```console |
| 219 | +sudo nerdctl rm uname |
| 220 | +``` |
| 221 | + |
| 222 | +To build a container image, use a text editor to copy the lines below to a new file named `Dockerfile`. |
| 223 | + |
| 224 | +```console |
| 225 | +FROM ubuntu:latest |
| 226 | +CMD echo -n "Architecture is " && uname -m |
| 227 | +``` |
| 228 | + |
| 229 | +Build the container image: |
| 230 | + |
| 231 | +```console |
| 232 | +sudo nerdctl build -t uname -f Dockerfile . |
| 233 | +``` |
| 234 | + |
| 235 | +Run the new container image: |
| 236 | + |
| 237 | +```console |
| 238 | +sudo nerdctl run uname |
| 239 | +``` |
| 240 | + |
| 241 | +The output is the architecture: |
| 242 | + |
| 243 | +```output |
| 244 | +Architecture is aarch64 |
| 245 | +``` |
| 246 | + |
| 247 | +## Basic nerdctl commands |
| 248 | + |
| 249 | +Here are some common commands to get you started: |
| 250 | + |
| 251 | +List running containers: |
| 252 | + |
| 253 | +```console |
| 254 | +sudo nerdctl ps |
| 255 | +``` |
| 256 | + |
| 257 | +List all containers (including stopped): |
| 258 | + |
| 259 | +```console |
| 260 | +sudo nerdctl ps -a |
| 261 | +``` |
| 262 | + |
| 263 | +List images: |
| 264 | + |
| 265 | +```console |
| 266 | +sudo nerdctl images |
| 267 | +``` |
| 268 | + |
| 269 | +Pull an image: |
| 270 | + |
| 271 | +```console |
| 272 | +sudo nerdctl pull <image_name>:<tag> |
| 273 | +``` |
| 274 | + |
| 275 | +Build an image from Dockerfile in current directory: |
| 276 | + |
| 277 | +```console |
| 278 | +sudo nerdctl build -t <image_name>:<tag> . |
| 279 | +``` |
| 280 | + |
| 281 | +Remove an image: |
| 282 | + |
| 283 | +```console |
| 284 | +sudo nerdctl rmi <image_name>:<tag> |
| 285 | +``` |
| 286 | + |
| 287 | +Stop a container: |
| 288 | + |
| 289 | +```console |
| 290 | +sudo nerdctl stop <container_name_or_id> |
| 291 | +``` |
| 292 | + |
| 293 | +Remove a container: |
| 294 | + |
| 295 | +```console |
| 296 | +sudo nerdctl rm <container_name_or_id> |
| 297 | +``` |
| 298 | + |
| 299 | +View container logs: |
| 300 | + |
| 301 | +```console |
| 302 | +sudo nerdctl logs <container_name_or_id> |
| 303 | +``` |
| 304 | + |
| 305 | +Execute a command in a running container: |
| 306 | + |
| 307 | +```console |
| 308 | +sudo nerdctl exec -it <container_name_or_id> <command> |
| 309 | +``` |
| 310 | + |
| 311 | +You are now ready to use nerdctl and containerd. |
0 commit comments