nerdctl - 兼容 Docker 语法 的 containerd 命令行界面

Nerdctl 是一个专为 containerd 环境设计的容器运行时工具,它与 Docker 语法兼容,提供了类似的命令行接口,但专注于更高效的容器管理。以下是关于 Nerdctl 的详细介绍:

nerdctl 是 containerd 的一个非核心子项目。

核心特点

  1. 轻量级设计:作为 containerd 的原生客户端,避免了不必要的组件层级,提升性能。
  2. Kubernetes 集成:无缝对接 Kubernetes 生态,支持 kubelet 直接调用。
  3. 兼容 Docker:大部分 Docker 命令可直接替换为 nerdctl 使用。
  4. 安全增强:默认启用 cgroups v2 和 seccomp 等安全特性。

基础命令示例

# 拉取镜像
nerdctl pull nginx:alpine

# 运行容器
nerdctl run -d -p 8080:80 --name web nginx:alpine

# 列出容器
nerdctl ps

# 构建镜像
nerdctl build -t myapp:v1 .

# 推送镜像
nerdctl push myapp:v1

与 Kubernetes 协同

Nerdctl 可直接操作 Kubernetes 节点上的容器:

# 在节点上执行命令
kubectl exec -it node-name -- bash
nerdctl ps  # 查看该节点上的所有容器

安装方法

下载地址:
https://github.com/containerd/nerdctl/releases

手动安装最新版本

# 1. 下载预编译二进制文件(替换为最新版本)
VERSION=$(curl -s https://api.github.com/repos/containerd/nerdctl/releases/latest | grep 'tag_name' | cut -d'"' -f4)
ARCH=$(uname -m)
curl -LO https://github.com/containerd/nerdctl/releases/download/${VERSION}/nerdctl-${VERSION#v}-linux-${ARCH}.tar.gz

# 2. 解压并安装
sudo tar -C /usr/local/bin -xzf nerdctl-${VERSION#v}-linux-${ARCH}.tar.gz

配置示例

完整参考:

https://github.com/containerd/nerdctl/blob/main/docs/config.md

修改 /etc/nerdctl/nerdctl.toml 配置文件:

# This is an example of /etc/nerdctl/nerdctl.toml .
# Unrelated to the daemon's /etc/containerd/config.toml .

debug          = false
debug_full     = false
address        = "unix:///run/k3s/containerd/containerd.sock"
namespace      = "k8s.io"
snapshotter    = "stargz"
cgroup_manager = "cgroupfs"
hosts_dir      = ["/etc/containerd/certs.d", "/etc/docker/certs.d"]
experimental   = true
userns_remap   = ""
dns            = ["8.8.8.8", "1.1.1.1"]
dns_opts       = ["ndots:1", "timeout:2"]
dns_search     = ["example.com", "example.org"]
Properties
TOML propertyCLI flagEnv varDescriptionAvailability
debug--debugDebug modeSince 0.16.0
debug_full--debug-fullDebug mode (with full output)Since 0.16.0
address--address,--host,-a,-H$CONTAINERD_ADDRESScontainerd addressSince 0.16.0
namespace--namespace,-n$CONTAINERD_NAMESPACEcontainerd namespaceSince 0.16.0
snapshotter--snapshotter,--storage-driver$CONTAINERD_SNAPSHOTTERcontainerd snapshotterSince 0.16.0
cni_path--cni-path$CNI_PATHCNI binary directorySince 0.16.0
cni_netconfpath--cni-netconfpath$NETCONFPATHCNI config directorySince 0.16.0
data_root--data-rootPersistent state directorySince 0.16.0
cgroup_manager--cgroup-managercgroup managerSince 0.16.0
insecure_registry--insecure-registryAllow insecure registrySince 0.16.0
hosts_dir--hosts-dircerts.d directorySince 0.16.0
experimental--experimentalNERDCTL_EXPERIMENTALEnable experimental featuresSince 0.22.3
host_gateway_ip--host-gateway-ipNERDCTL_HOST_GATEWAY_IPIP address that the special ‘host-gateway’ string in --add-host resolves to. Defaults to the IP address of the host. It has no effect without setting --add-hostSince 1.3.0
bridge_ip--bridge-ipNERDCTL_BRIDGE_IPIP address for the default nerdctl bridge network, e.g., 10.1.100.1/24Since 2.0.1
kube_hide_dupe--kube-hide-dupeDeduplicate images for Kubernetes with namespace k8s.io, no more redundant ones are displayedSince 2.0.3
cdi_spec_dirs--cdi-spec-dirsThe folders to use when searching for CDI (container-device-interface) specifications.Since 2.1.0
userns_remap--userns-remapSupport idmapping of containers. This options is only supported on rootful linux. If host is passed, no idmapping is done. if a user name is passed, it does idmapping based on the uidmap and gidmap ranges specified in /etc/subuid and /etc/subgid respectively.Since 2.1.0
dnsSet global DNS servers for containersSince 2.1.3
dns_optsSet global DNS options for containersSince 2.1.3
dns_searchSet global DNS search domains for containersSince 2.1.3
<think>嗯,用户的问题是关于如何解析pstree命令输出中dockercontainerd的进程结构。我需要结合提供的引用资料来组织答案。首先,用户提到他们想查找与dockercontainerd相关的进程树信息,所以应该先解释pstree命令的基本使用,然后分析进程结构。 根据引用[1],当Docker daemon启动后,dockerd和docker-containerd进程会一直存在。启动容器后,docker-containerd会创建docker-containerd-shim进程,参数包含容器ID。而最终的容器进程如sleep 1000是shim的子进程。引用[2]中的pstree输出示例展示了dockerd、containerdcontainerd-shim和容器进程的层次结构,这里需要详细解析每个组件的作用。 引用[4]提到从Docker 1.11开始,架构变化,containerd负责容器生命周期管理。因此,在进程树中,containerd作为独立组件出现,dockerd作为客户端代理,而containerd-shim管理具体容器进程。引用[3]中的ps和pstree命令输出显示containerd-shim直接运行容器进程如bash。 接下来,需要分步骤解释如何解析进程树。第一步是识别核心进程dockerd和containerd,然后查看containerd的子进程,通常是shim进程,每个对应一个容器。最后,shim的子进程是容器内的实际进程。还需要注意参数中的容器ID,如引用[1]中的例子,容器ID出现在shim进程的参数中。 用户可能需要知道如何通过进程树查看正在运行的容器及其对应进程,以及各组件之间的关系。所以,在回答中要强调dockerd作为守护进程,containerd作为中间层,shim作为容器运行时接口,容器进程由shim启动。同时,结合引用中的例子,说明参数的作用和进程层级。 最后,生成相关问题时要围绕Docker架构、组件功能、进程树分析命令和组件间通信方式展开。确保问题能帮助用户进一步理解相关知识。</think>### Docker/containerd进程树解析步骤 #### 一、理解Docker架构演进(关键背景) 从Docker 1.11开始采用分层架构: $$dockerd \rightarrow containerd \rightarrow containerd-shim \rightarrow 容器进程$$ 其中containerd成为独立组件负责容器生命周期管理,dockerd作为客户端代理与用户交互[^4] #### 二、解析进程树的关键模式 使用`pstree -aps <PID>`或`pstree -a`观察典型结构: ``` systemd,1 └─dockerd,主进程ID -H fd:// --storage-driver=overlay2 └─docker-containerd,子进程ID -l unix://...containerd.sock └─docker-containerd-shim,孙进程ID -namespace moby -id 容器ID └─实际容器进程,玄孙进程ID ``` (参考引用[1][2][3]中的进程树示例) #### 三、关键组件解析表 | 进程名称 | 作用 | 参数特征 | |-------------------------|----------------------------------------------------------------------|--------------------------------------------------------------------------| | dockerd | Docker守护进程,处理API请求 | 包含`-H`指定监听方式,`--storage-driver`存储驱动配置 | | docker-containerd | 容器运行时主进程(现多简化为containerd) | 包含`-l`指定socket路径,`--state-dir`状态目录 | | docker-containerd-shim | 容器生命周期管理桥接层(现多为containerd-shim-runc-v2) | 包含`-namespace`和`-id 容器ID`,直接关联特定容器 | | 容器进程 | 容器内实际运行的进程(如/bin/bash、sleep等) | 显示原始命令(如sleep 1000),无特殊参数 | #### 四、操作验证示例 通过`ps aux | grep containerd`可验证: ``` root 12345 0.1 0.2 701234 45678 ? Ssl May01 10:20 /usr/bin/containerd root 23456 0.0 0.0 123456 1234 ? Sl May02 0:01 containerd-shim -namespace moby -id xxxx... ``` (参考引用[3]中的实际进程输出) #### 五、特殊场景说明 1. **Kubernetes集成**:当使用CRI(容器运行时接口)时,会出现`containerd cri`等分支进程 2. **多容器实例**:每个容器对应独立的shim进程和容器进程树 3. **版本差异**:新版本可能显示为`containerd-shim-runc-v2`而非`docker-containerd-shim`[^3]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值