github.com/containerd/nerdctl@v1.7.7/docs/faq.md (about)

     1  # FAQs and Troubleshooting
     2  
     3  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
     4  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
     5  
     6  - [Project](#project)
     7    - [How is nerdctl different from `docker` ?](#how-is-nerdctl-different-from-docker-)
     8    - [How is nerdctl different from `ctr` and `crictl` ?](#how-is-nerdctl-different-from-ctr-and-crictl-)
     9  - [Mac & Windows](#mac--windows)
    10    - [Does nerdctl run on macOS ?](#does-nerdctl-run-on-macos-)
    11    - [Does nerdctl run on Windows ?](#does-nerdctl-run-on-windows-)
    12  - [Configuration](#configuration)
    13    - [nerdctl ignores `[plugins."io.containerd.grpc.v1.cri"]` config](#nerdctl-ignores-pluginsiocontainerdgrpcv1cri-config)
    14    - [How to login to a registry?](#how-to-login-to-a-registry)
    15    - [How to use a non-HTTPS registry?](#how-to-use-a-non-https-registry)
    16    - [How to specify the CA certificate of the registry?](#how-to-specify-the-ca-certificate-of-the-registry)
    17    - [How to change the cgroup driver?](#how-to-change-the-cgroup-driver)
    18    - [How to change the snapshotter?](#how-to-change-the-snapshotter)
    19    - [How to change the runtime?](#how-to-change-the-runtime)
    20    - [How to change the CNI binary path?](#how-to-change-the-cni-binary-path)
    21  - [Kubernetes](#kubernetes)
    22    - [`nerdctl ps -a` does not show Kubernetes containers](#nerdctl-ps--a-does-not-show-kubernetes-containers)
    23    - [How to build an image for Kubernetes?](#how-to-build-an-image-for-kubernetes)
    24  - [containerd socket address](#containerd-socket-address)
    25    - [Does nerdctl have an equivalent of `DOCKER_HOST=ssh://<USER>@<REMOTEHOST>` ?](#does-nerdctl-have-an-equivalent-of-docker_hostsshuserremotehost-)
    26    - [Does nerdctl have an equivalent of `sudo usermod -aG docker <USER>` ?](#does-nerdctl-have-an-equivalent-of-sudo-usermod--ag-docker-user-)
    27  - [Rootless](#rootless)
    28    - [How to use nerdctl as a non-root user? (Rootless mode)](#how-to-use-nerdctl-as-a-non-root-user-rootless-mode)
    29    - [`nerdctl run -p <PORT>` does not propagate source IP](#nerdctl-run--p-port-does-not-propagate-source-ip)
    30    - [`nerdctl run -p <PORT>` does not work with port numbers below 1024](#nerdctl-run--p-port-does-not-work-with-port-numbers-below-1024)
    31    - [Can't ping](#cant-ping)
    32    - [Containers do not automatically start after rebooting the host](#containers-do-not-automatically-start-after-rebooting-the-host)
    33    - [Error `failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: unable to apply cgroup configuration: unable to start unit ... {Name:Slice Value:"user.slice"} {Name:Delegate Value:true} ... Permission denied: unknown`](#error-failed-to-create-shim-task-oci-runtime-create-failed-runc-create-failed-unable-to-start-container-process-unable-to-apply-cgroup-configuration-unable-to-start-unit--nameslice-valueuserslice-namedelegate-valuetrue--permission-denied-unknown)
    34    - [How to uninstall ? / Can't remove `~/.local/share/containerd`](#how-to-uninstall---cant-remove-localsharecontainerd)
    35  
    36  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
    37  
    38  ## Project
    39  
    40  ### How is nerdctl different from `docker` ?
    41  
    42  The goal of nerdctl is to facilitate experimenting the cutting-edge features of containerd that are not present in Docker.
    43  
    44  Such features include, but not limited to, [on-demand image pulling (lazy-pulling)](./stargz.md) and [image encryption/decryption](./ocicrypt.md).
    45  See also [`../README.md`](../README.md) for the list of the features present in nerdctl but not present in Docker (and vice versa).
    46  
    47  Note that competing with Docker is _not_ the goal of nerdctl. Those cutting-edge features are expected to be eventually available in Docker as well.
    48  
    49  ### How is nerdctl different from `ctr` and `crictl` ?
    50  
    51  [`ctr`](https://github.com/containerd/containerd/tree/main/cmd/ctr) is a debugging utility bundled with containerd.
    52  
    53  ctr is incompatible with Docker CLI, and not friendly to users.
    54  
    55  Notably, `ctr` lacks the equivalents of the following nerdctl commands:
    56  - `nerdctl run -p <PORT>`
    57  - `nerdctl run --restart=always --net=bridge`
    58  - `nerdctl pull` with `~/.docker/config.json` and credential helper binaries such as `docker-credential-ecr-login`
    59  - `nerdctl logs`
    60  - `nerdctl build`
    61  - `nerdctl compose up`
    62  
    63  [`crictl`](https://github.com/kubernetes-sigs/cri-tools) has similar restrictions too.
    64  
    65  ## Mac & Windows
    66  
    67  ### Does nerdctl run on macOS ?
    68  
    69  Yes, via a Linux virtual machine.
    70  
    71  [Lima](https://github.com/lima-vm/lima) project provides Linux virtual machines for macOS, with built-in integration for nerdctl.
    72  
    73  ```console
    74  $ brew install lima
    75  $ limactl start
    76  $ lima nerdctl run -d --name nginx -p 127.0.0.1:8080:80 nginx:alpine
    77  ```
    78  
    79  [Rancher Desktop for Mac](https://rancherdesktop.io/) and [colima](https://github.com/abiosoft/colima) also provide custom Lima machines with nerdctl.
    80  
    81  ### Does nerdctl run on Windows ?
    82  
    83  Windows containers: Yes, but experimental.
    84  
    85  Linux containers: Yes, via WSL2. [Rancher Desktop for Windows](https://rancherdesktop.io/) provides a `nerdctl.exe` that wraps nerdctl binary in a WSL2 machine.
    86  
    87  ## Configuration
    88  
    89  ### nerdctl ignores `[plugins."io.containerd.grpc.v1.cri"]` config
    90  
    91  Expected behavior, because nerdctl does not use CRI (Kubernetes Container Runtime Interface) API.
    92  
    93  See the questions below for how to configure nerdctl.
    94  
    95  ### How to login to a registry?
    96  
    97  Use `nerdctl login`, or just create `~/.docker/config.json`.
    98  nerdctl also supports credential helper binaries such as `docker-credential-ecr-login`.
    99  
   100  ### How to use a non-HTTPS registry?
   101  
   102  Use `nerdctl --insecure-registry run <IMAGE>`. See also [`registry.md`](./registry.md).
   103  
   104  ### How to specify the CA certificate of the registry?
   105  
   106  | :zap: Requirement | nerdctl >= 0.16 |
   107  |-------------------|-----------------|
   108  
   109  Create `~/.config/containerd/certs.d/<HOST:PORT>/hosts.toml` (or `/etc/containerd/certs.d/...` for rootful) to specify `ca` certificates.
   110  
   111  ```toml
   112  # An example of ~/.config/containerd/certs.d/192.168.12.34:5000/hosts.toml
   113  # (The path is "/etc/containerd/certs.d/192.168.12.34:5000/hosts.toml" for rootful)
   114  
   115  server = "https://192.168.12.34:5000"
   116  [host."https://192.168.12.34:5000"]
   117    ca = "/path/to/ca.crt"
   118  ```
   119  
   120  See https://github.com/containerd/containerd/blob/main/docs/hosts.md for the syntax of `hosts.toml` .
   121  
   122  Docker-style directories are also supported.
   123  The path is `~/.config/docker/certs.d` for rootless, `/etc/docker/certs.d` for rootful.
   124  
   125  See also [`registry.md`](./registry.md).
   126  
   127  ### How to change the cgroup driver?
   128  
   129  - Option 1: `nerdctl --cgroup-manager=(cgroupfs|systemd|none)`.
   130  - Option 2: Set `cgroup_manager` property in [`nerdctl.toml`](config.md)
   131  
   132  The default value is `systemd` on cgroup v2 hosts (both rootful and rootless), `cgroupfs` on cgroup v1 rootful hosts, `none` on cgroup v1 rootless hosts.
   133  
   134  <details>
   135  <summary>Hint: The corresponding configuration for Kubernetes (<code>io.containerd.grpc.v1.cri</code>)</summary>
   136  
   137  <p>
   138  
   139  ```toml
   140  # An example of /etc/containerd/config.toml for Kubernetes
   141  version = 2
   142  [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
   143    SystemdCgroup = true
   144  ```
   145  
   146  In addition to containerd, you have to configure kubelet too:
   147  
   148  ```yaml
   149  # An example of /var/lib/kubelet/config.yaml for Kubernetes
   150  kind: KubeletConfiguration
   151  apiVersion: kubelet.config.k8s.io/v1beta1
   152  cgroupDriver: "systemd"
   153  ```
   154  See also https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/configure-cgroup-driver/
   155  
   156  </p>
   157  </details>
   158  
   159  ### How to change the snapshotter?
   160  - Option 1: Use `nerdctl --snapshotter=(overlayfs|native|btrfs|...)`
   161  - Option 2: Set `$CONTAINERD_SNAPSHOTTER`
   162  - Option 3: Set `snapshotter` property in [`nerdctl.toml`](config.md)
   163  
   164  The default value is `overlayfs`.
   165  
   166  <details>
   167  <summary>Hint: The corresponding configuration for Kubernetes (<code>io.containerd.grpc.v1.cri</code>)</summary>
   168  
   169  <p>
   170  
   171  ```toml
   172  # An example of /etc/containerd/config.toml for Kubernetes
   173  version = 2
   174  [plugins."io.containerd.grpc.v1.cri".containerd]
   175    snapshotter = "overlayfs"
   176  ```
   177  
   178  </p>
   179  </details>
   180  
   181  ### How to change the runtime?
   182  Use `nerdctl run --runtime=<RUNTIME>`.
   183  
   184  The `<RUNTIME>` string can be either a containerd runtime plugin name (such as `io.containerd.runc.v2`),
   185  or a path to a runc-compatible binary (such as `/usr/local/sbin/runc`).
   186  
   187  <details>
   188  <summary>Hint: The corresponding configuration for Kubernetes (<code>io.containerd.grpc.v1.cri</code>)</summary>
   189  
   190  <p>
   191  
   192  ```toml
   193  # An example of /etc/containerd/config.toml for Kubernetes
   194  version = 2
   195  [plugins."io.containerd.grpc.v1.cri".containerd]
   196    default_runtime_name = "crun"
   197    [plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
   198      [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun]
   199        runtime_type = "io.containerd.runc.v2"
   200        [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun.options]
   201          BinaryName = "/usr/local/bin/crun"
   202  ```
   203  
   204  </p>
   205  </details>
   206  
   207  
   208  ### How to change the CNI binary path?
   209  
   210  - Option 1: Use `nerdctl --cni-path=<PATH>`
   211  - Option 2: Set `$CNI_PATH`
   212  - Option 3: Set `cni_path` property in [`nerdctl.toml`](config.md).
   213  
   214  The default value is automatically detected by checking the following candidates:
   215  - `~/.local/libexec/cni`
   216  - `~/.local/lib/cni`
   217  - `~/opt/cni/bin`
   218  - `/usr/local/libexec/cni`
   219  - `/usr/local/lib/cni`
   220  - `/usr/libexec/cni`
   221  - `/usr/lib/cni`
   222  - `/opt/cni/bin`
   223  
   224  <details>
   225  <summary>Hint: The corresponding configuration for Kubernetes (<code>io.containerd.grpc.v1.cri</code>)</summary>
   226  
   227  <p>
   228  
   229  ```toml
   230  # An example of /etc/containerd/config.toml for Kubernetes
   231  version = 2
   232  [plugins."io.containerd.grpc.v1.cri".cni]
   233     bin_dir = "/opt/cni/bin"
   234  ```
   235  
   236  </p>
   237  </details>
   238  
   239  
   240  ## Kubernetes
   241  
   242  ### `nerdctl ps -a` does not show Kubernetes containers
   243  Try `sudo nerdctl --namespace=k8s.io ps -a` .
   244  
   245  Note: k3s users have to specify `--address` too: `sudo nerdctl --address=/run/k3s/containerd/containerd.sock --namespace=k8s.io ps -a`
   246  
   247  ### How to build an image for Kubernetes?
   248  
   249  For a multi-node cluster:
   250  ```console
   251  $ nerdctl build -t example.com/foo /some-dockerfile-directory
   252  $ nerdctl push example.com/foo
   253  ```
   254  
   255  For a single-node cluster w/o registry:
   256  ```console
   257  # nerdctl --namespace k8s.io build -t foo /some-dockerfile-directory
   258  # kubectl apply -f - <<EOF
   259  apiVersion: v1
   260  kind: Pod
   261  metadata:
   262    name: foo
   263  spec:
   264    containers:
   265      - name: foo
   266        image: foo
   267        imagePullPolicy: Never
   268  EOF
   269  ```
   270  
   271  ## containerd socket address
   272  
   273  - rootful: `/run/containerd/containerd.sock`
   274  - rootless (e.g., default [Lima](https://github.com/lima-vm/lima) instance): `/proc/<PID of containerd>/root/run/containerd/containerd.sock`, or you can run this command to find out: `echo /proc/$(cat $XDG_RUNTIME_DIR/containerd-rootless/child_pid)/root/run/containerd/containerd.sock` (why it works:  [`rootlessutil.ParentMain`](https://github.com/containerd/nerdctl/blob/b160d8173fb765b76cf0920d26621843d377bc3f/pkg/rootlessutil/parent.go#L66))
   275  
   276  ### Does nerdctl have an equivalent of `DOCKER_HOST=ssh://<USER>@<REMOTEHOST>` ?
   277  
   278  No. Just use `ssh -l <USER> <REMOTEHOST> nerdctl`.
   279  
   280  ### Does nerdctl have an equivalent of `sudo usermod -aG docker <USER>` ?
   281  
   282  Not exactly same, but setting SETUID bit (`chmod +s`) on `nerdctl` binary gives similar user experience.
   283  
   284  ```
   285  mkdir -p $HOME/bin
   286  chmod 700 $HOME/bin
   287  cp /usr/local/bin/nerdctl $HOME/bin
   288  sudo chown root $HOME/bin/nerdctl
   289  sudo chmod +s $HOME/bin/nerdctl
   290  export PATH=$HOME/bin:$PATH
   291  ```
   292  
   293  Chmodding `$HOME/bin` to `700` is important, otherwise an unintended user may gain the root privilege via the SETUID bit.
   294  
   295  Using SETUID bit is highly discouraged. Consider using [Rootless mode](#rootless) instead whenever possible.
   296  
   297  ## Rootless
   298  
   299  ### How to use nerdctl as a non-root user? (Rootless mode)
   300  
   301  ```
   302  containerd-rootless-setuptool.sh install
   303  nerdctl run -d --name nginx -p 8080:80 nginx:alpine
   304  ```
   305  
   306  See also:
   307  - [`rootless.md`](./rootless.md)
   308  - https://rootlesscontaine.rs/getting-started/common/
   309  - https://rootlesscontaine.rs/getting-started/containerd/
   310  
   311  ### `nerdctl run -p <PORT>` does not propagate source IP
   312  Expected behavior with the default `rootlesskit` port driver.
   313  
   314  The solution is to change the port driver to `slirp4netns` (sacrifices performance).
   315  
   316  See https://rootlesscontaine.rs/getting-started/containerd/#changing-the-port-forwarder .
   317  
   318  ### `nerdctl run -p <PORT>` does not work with port numbers below 1024
   319  
   320  Set sysctl value `net.ipv4.ip_unprivileged_port_start=0` .
   321  
   322  See https://rootlesscontaine.rs/getting-started/common/sysctl/#optional-allowing-listening-on-tcp--udp-ports-below-1024
   323  
   324  ### Can't ping
   325  
   326  Set sysctl value `net.ipv4.ping_group_range=0 2147483647` .
   327  
   328  See https://rootlesscontaine.rs/getting-started/common/sysctl/#optional-allowing-ping
   329  
   330  ### Containers do not automatically start after rebooting the host
   331  Run `sudo loginctl enable-linger $(whoami)` .
   332  
   333  See https://rootlesscontaine.rs/getting-started/common/login/ .
   334  
   335  ### Error `failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: unable to apply cgroup configuration: unable to start unit ... {Name:Slice Value:"user.slice"} {Name:Delegate Value:true} ... Permission denied: unknown`
   336  
   337  Running a rootless container with `systemd` cgroup driver requires dbus to be running as a user session service.
   338  
   339  Otherwise runc may fail with an error like below:
   340  ```
   341  FATA[0000] failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: unable to apply cgroup configuration: unable to start unit "nerdctl-7bda4abaa1f006ab9feeb98c06953db43f212f1c0aaf658fb8a88d6f63dff9f9.scope" (properties [{Name:Description Value:"libcontainer container 7bda4abaa1f006ab9feeb98c06953db43f212f1c0aaf658fb8a88d6f63dff9f9"} {Name:Slice Value:"user.slice"} {Name:Delegate Value:true} {Name:PIDs Value:@au [1154]} {Name:MemoryAccounting Value:true} {Name:CPUAccounting Value:true} {Name:IOAccounting Value:true} {Name:TasksAccounting Value:true} {Name:DefaultDependencies Value:false}]): Permission denied: unknown
   342  ```
   343  
   344  Solution:
   345  ```
   346  sudo apt-get install -y dbus-user-session
   347  
   348  systemctl --user start dbus
   349  ```
   350  
   351  ### How to uninstall ? / Can't remove `~/.local/share/containerd`
   352  
   353  Run the following commands:
   354  ```
   355  containerd-rootless-setuptool.sh uninstall
   356  rootlesskit rm -rf ~/.local/share/containerd ~/.local/share/nerdctl ~/.config/containerd
   357  ```