graph TD
U[用户命令 nerdctl run/compose/build] --> P[CLI 参数解析与校验]
P -->|"run/ps/logs 等"| C[containerd gRPC 客户端]
P -->|"build"| B[BuildKit 客户端]
P -->|"compose up"| O[Compose 编排解析]
O --> C
C -->|"namespace 隔离"| D[containerd daemon]
B --> K[buildkitd]
D --> S[snapshotter 插件<br/>stargz/nydus/overlaybd]
D --> N[CNI 网络插件]
D --> R[runc 创建容器进程]
R --> W[运行中的容器]
*1: P2P image distribution (IPFS) is completely optional. Your host is NOT connected to any P2P network, unless you opt in to install and run IPFS daemon.
Examples
Basic usage
To run a container with the default bridge CNI network (10.4.0.0/24):
Namespacing: nerdctl --namespace=<NS> ps .
(NOTE: All Kubernetes containers are in the k8s.io containerd namespace regardless to Kubernetes namespaces)
Exporting Docker/OCI dual-format archives: nerdctl save .
Importing OCI archives as well as Docker archives: nerdctl load .
Specifying a non-image rootfs: nerdctl run -it --rootfs <ROOTFS> /bin/sh . The CLI syntax conforms to Podman convention.
Connecting a container to multiple networks at once: nerdctl run --net foo --net bar
Applying an (existing) AppArmor profile to rootless containers: nerdctl run --security-opt apparmor=<PROFILE>.
Use sudo nerdctl apparmor load to load the nerdctl-default profile.
Systemd compatibility support: nerdctl run --systemd=always
Trivial:
Inspecting raw OCI config: nerdctl container inspect --mode=native .
Features implemented in nerdctl ahead of Docker
Recursive read-only (RRO) bind-mount: nerdctl run -v /mnt:/mnt:rro (make children such as /mnt/usb to be read-only, too).
Requires kernel >= 5.12.
The same feature was later introduced in Docker v25 with a different syntax: read-only mounts are now recursively read-only by default when supported,
and the behavior is customizable with --mount type=bind,...,readonly,bind-recursive=<enabled|disabled|writable|readonly>.
nerdctl now supports the Docker v25 syntax too, and the old rro syntax is deprecated.
Similar tools
ctr: incompatible with Docker CLI, and not friendly to users.
Notably, ctr lacks the equivalents of the following nerdctl commands:
nerdctl run -p <PORT>
nerdctl run --restart=always --net=bridge
nerdctl pull with ~/.docker/config.json and credential helper binaries such as docker-credential-ecr-login
nerdctl logs
nerdctl build
nerdctl compose up
crictl: incompatible with Docker CLI, not friendly to users, and does not support non-CRI features
k3c v0.2 (abandoned): needs an extra daemon, and does not support non-CRI features
Rancher Kim (nee k3c v0.3): needs Kubernetes, and only focuses on image management commands such as kim build and kim push
See the header of go.mod for the minimum supported version of Go.
Using go install github.com/containerd/nerdctl/v2/cmd/nerdctl is possible, but unrecommended because it does not fill version strings printed in nerdctl version
评论