nerdctl命令速查
全局参数、容器运行管理、镜像与构建、Compose 编排、CNI 网络、k8s.io 命名空间与排障等 135 条命令
共 135 条命令 · 10 类场景 · 点击右侧图标可复制
| 命令 / 配置 | 说明 | 复制 |
|---|---|---|
nerdctl version | 查看客户端、containerd 与 CNI 版本 | |
nerdctl info | 查看运行时信息:socket、命名空间、snapshotter | |
nerdctl --address /run/containerd/containerd.sock ps | 显式指定 containerd socket | |
nerdctl --namespace k8s.io ps | 查看 Kubernetes 管理的容器(K8s 默认使用 k8s.io 命名空间) | |
nerdctl namespace ls | 列出 containerd 中全部命名空间 | |
nerdctl -n default ps | 简写方式切换命名空间 | |
nerdctl --debug ps | 输出调试日志,排查连接与 CNI 问题 | |
cat /etc/nerdctl/nerdctl.toml | 查看全局配置(默认 namespace、address、CNI 路径) | |
namespace = "k8s.io" 与 address = "/run/containerd/containerd.sock" | 写入 nerdctl.toml 可免去每次带参数 | |
nerdctl completion bash > /etc/bash_completion.d/nerdctl | 开启命令补全 | |
nerdctl system info | 查看系统级信息与存储驱动 | |
nerdctl --help | 查看全部子命令,多数与 docker 保持一致 |
| 命令 / 配置 | 说明 | 复制 |
|---|---|---|
nerdctl run -d --name web -p 8080:80 nginx:1.25 | 后台运行并映射端口,最常用的启动方式 | |
nerdctl run -it --rm ubuntu:22.04 bash | 交互式临时容器,退出即删除 | |
nerdctl run -d -v /data/app:/app -w /app app:v1 | 挂载目录并指定工作目录 | |
nerdctl run -d -e APP_ENV=prod -e TZ=Asia/Shanghai app:v1 | 注入环境变量 | |
nerdctl run -d --network mynet --ip 10.10.0.10 app:v1 | 加入自定义网络并指定固定 IP | |
nerdctl run -d --net host nginx:1.25 | 使用宿主机网络(端口直接占用宿主机) | |
nerdctl run -d --restart=always --name web nginx:1.25 | 设置重启策略 | |
nerdctl run -d --cpus 2 --memory 1g app:v1 | 限制 CPU 与内存 | |
nerdctl run -d --platform linux/amd64 app:v1 | 指定平台,跨架构节点上常用 | |
nerdctl run -d --pull always app:v1 | 强制先拉取最新镜像 | |
nerdctl run -d --label env=prod --label app=api app:v1 | 打标签便于筛选与管理 | |
nerdctl run -d --privileged nginx:1.25 | 特权模式(安全风险大,仅在调试时使用) | |
nerdctl run -d --entrypoint /bin/sh app:v1 -c "sleep 3600" | 覆盖镜像入口点 | |
nerdctl create --name web nginx:1.25 | 只创建不启动,随后用 start 启动 | |
nerdctl start web 与 nerdctl stop web 与 nerdctl restart web | 容器生命周期基础操作 |
| 命令 / 配置 | 说明 | 复制 |
|---|---|---|
nerdctl ps | 列出运行中的容器 | |
nerdctl ps -a | 包含已退出的容器 | |
nerdctl ps -q | 只输出容器 ID | |
nerdctl ps --format "{{.Names}}\t{{.Status}}\t{{.Ports}}" | 自定义输出列,便于脚本处理 | |
nerdctl inspect web | 查看容器完整配置(JSON) | |
nerdctl inspect web | jq .[0].State | 提取运行状态 | |
nerdctl logs -f --tail 100 web | 跟踪最近 100 行日志 | |
nerdctl logs --since 10m --timestamps web | 按时间范围查看并带时间戳 | |
nerdctl exec -it web sh | 进入容器交互式 shell | |
nerdctl exec web env | 查看容器环境变量 | |
nerdctl stats --no-stream | 查看 CPU、内存、网络与磁盘占用快照 | |
nerdctl top web | 查看容器内进程列表 | |
nerdctl port web | 查看端口映射关系 | |
nerdctl rm -f web | 强制删除容器(含运行中) | |
nerdctl container prune | 清理全部已退出容器 | |
nerdctl commit web app:snapshot | 把容器当前状态提交为镜像 | |
nerdctl pause web 与 nerdctl unpause web | 暂停与恢复容器进程 |
| 命令 / 配置 | 说明 | 复制 |
|---|---|---|
nerdctl images | 列出本地镜像(含 REPOSITORY、TAG、IMAGE ID、SIZE) | |
nerdctl images --digests | 显示 digest,核对镜像是否被覆盖 | |
nerdctl images --format "{{.Repository}}:{{.Tag}} {{.Size}}" | 自定义输出,快速统计镜像体积 | |
nerdctl pull nginx:1.25 | 拉取镜像 | |
nerdctl pull --platform linux/arm64 nginx:1.25 | 拉取指定架构镜像 | |
nerdctl login -u admin registry.example.com | 登录私有仓库(凭据写入 docker config) | |
nerdctl login -u admin -p 密码 registry.example.com | 非交互登录,适合脚本(注意命令历史泄露) | |
nerdctl logout registry.example.com | 退出登录并清理凭据 | |
nerdctl tag nginx:1.25 registry.example.com/app/nginx:1.25 | 打标签,推送前必须带仓库地址 | |
nerdctl push registry.example.com/app/nginx:1.25 | 推送镜像到仓库 | |
nerdctl rmi nginx:1.25 | 删除指定镜像 | |
nerdctl image prune -a | 清理所有未被容器使用的镜像,释放磁盘 | |
nerdctl save -o nginx.tar nginx:1.25 | 导出镜像为 tar,离线分发用 | |
nerdctl load -i nginx.tar | 从 tar 导入镜像 | |
nerdctl history nginx:1.25 | 查看镜像分层与构建历史 | |
nerdctl inspect nginx:1.25 | 查看镜像详细信息(与容器 inspect 共用该命令) |
| 命令 / 配置 | 说明 | 复制 |
|---|---|---|
nerdctl build -t app:v1 . | 使用 BuildKit 构建镜像(需安装 buildkit) | |
nerdctl build -t app:v1 -f Dockerfile.prod . | 指定 Dockerfile 路径 | |
nerdctl build --build-arg HTTP_PROXY=http://proxy:8080 -t app:v1 . | 传入构建参数 | |
nerdctl build --target builder -t app:v1 . | 多阶段构建只构建指定阶段 | |
nerdctl build --no-cache -t app:v1 . | 禁用缓存,排查缓存导致的异常 | |
nerdctl build --progress plain -t app:v1 . | 输出明文构建日志,CI 中便于排查 | |
nerdctl build --secret id=npmrc,src=$HOME/.npmrc -t app:v1 . | 安全注入构建密钥,不落镜像层 | |
nerdctl build --ssh default -t app:v1 . | 允许构建过程使用 SSH 拉取私有依赖 | |
nerdctl build --platform linux/amd64,linux/arm64 -t app:v1 --push . | 多架构构建并直接推送 | |
systemctl status buildkit | 确认 BuildKit 服务运行,构建失败先看这里 | |
buildctl debug workers | 查看 BuildKit worker 与支持的平台 | |
nerdctl build 需要 buildkitd,纯 containerd 环境不会自带 | rootless 模式需额外部署 buildkit 用户服务 | |
nerdctl compose build | 按 compose 文件批量构建服务镜像 |
| 命令 / 配置 | 说明 | 复制 |
|---|---|---|
nerdctl compose up -d | 后台启动 compose 定义的全部服务 | |
nerdctl compose -f app.yaml up -d | 指定 compose 文件 | |
nerdctl compose ps | 查看服务与容器状态 | |
nerdctl compose logs -f web | 跟踪指定服务日志 | |
nerdctl compose exec web sh | 进入服务容器 | |
nerdctl compose restart web | 重启指定服务 | |
nerdctl compose pull | 拉取全部服务镜像 | |
nerdctl compose config | 输出解析合并后的最终配置 | |
nerdctl compose down | 停止并删除服务容器与网络 | |
nerdctl compose down -v | 同时删除数据卷(数据会丢失) | |
nerdctl compose --project-name demo up -d | 指定项目名,便于多套环境隔离 | |
部分 docker compose 字段 nerdctl 尚不支持,先 config 验证 | 复杂编排建议直接改用 Kubernetes |
| 命令 / 配置 | 说明 | 复制 |
|---|---|---|
nerdctl network ls | 列出 CNI 网络 | |
nerdctl network create --subnet 10.10.0.0/24 mynet | 创建自定义网络与子网 | |
nerdctl network inspect mynet | 查看网络详情与已连接容器 | |
nerdctl network rm mynet | 删除网络(需先断开容器) | |
nerdctl run -d --network mynet --name web nginx:1.25 | 把容器加入自定义网络 | |
nerdctl run -d --net none app:v1 | 不使用网络,仅本地回环 | |
nerdctl run -d --net host app:v1 | 共享宿主机网络栈 | |
nerdctl run -d --dns 8.8.8.8 app:v1 | 指定容器 DNS | |
nerdctl exec web ip addr | 查看容器内网卡与 IP(镜像需含 iproute2) | |
nerdctl exec web cat /etc/resolv.conf | 确认 DNS 配置是否正确注入 | |
ls /etc/cni/net.d | 查看 CNI 配置文件,nerdctl 依赖这些配置创建网络 | |
nerdctl network prune | 清理未使用的网络 | |
K8s 节点上的 CNI 配置可能影响 nerdctl network create | 冲突时优先使用默认 bridge 网络 | |
nerdctl port web | 确认端口映射是否生效 |
| 命令 / 配置 | 说明 | 复制 |
|---|---|---|
nerdctl -n k8s.io ps -a | 查看 K8s 节点上全部容器(crictl 之外的另一种视角) | |
nerdctl -n k8s.io images | 查看 kubelet 拉取的镜像 | |
nerdctl -n k8s.io logs <container-id> | 直接看容器日志 | |
nerdctl -n k8s.io exec -it <container-id> sh | 进入业务容器排查 | |
nerdctl -n k8s.io inspect <container-id> | 查看底层配置,包含 CNI 与挂载信息 | |
nerdctl namespace ls | 确认 k8s.io 命名空间是否存在 | |
nerdctl -n k8s.io image prune -a | 清理节点镜像前先确认 kubelet GC 策略(慎用) | |
nerdctl -n k8s.io ps --format "{{.Names}}" | 只输出名称,便于批量处理 | |
默认命名空间 default 与 K8s 的 k8s.io 相互隔离 | 看不到容器多半是命名空间选错 | |
crictl 面向 CRI 接口,nerdctl 面向 containerd 原生 API | K8s 排障优先 crictl,镜像与 build 场景用 nerdctl | |
nerdctl -n k8s.io pull registry.example.com/app:v1 | 预拉镜像,减少 Pod 启动时间 | |
kubelet 使用同一 containerd 时,nerdctl 可直接操作其数据 | 手工删除容器前确认不会破坏工作负载 |
| 命令 / 配置 | 说明 | 复制 |
|---|---|---|
nerdctl system df | 查看镜像、容器、卷与构建缓存占用 | |
nerdctl system prune | 清理未使用的容器、网络与悬空镜像 | |
nerdctl system prune -a --volumes | 彻底清理(含未被引用的卷,数据会丢失) | |
nerdctl volume ls | 列出数据卷 | |
nerdctl volume create appdata | 创建数据卷 | |
nerdctl volume rm appdata | 删除数据卷 | |
nerdctl run -d -v appdata:/data app:v1 | 挂载命名卷 | |
nerdctl info | grep -i snapshotter | 确认存储快照驱动(overlayfs 最常见) | |
du -sh /var/lib/containerd | 宿主机侧查看运行时数据目录占用 | |
df -h /var/lib/containerd | 磁盘不足会直接导致拉取与构建失败 | |
nerdctl images --format "{{.Size}}" | head | 快速估算镜像体积分布 |
| 命令 / 配置 | 说明 | 复制 |
|---|---|---|
failed to connect to containerd | socket 路径错误或服务未启动:核对 nerdctl.toml 与 systemctl status containerd | |
permission denied while connecting to socket | 当前用户无权访问 socket,用 sudo 或将用户加入相应组 | |
namespace k8s.io: not found | kubelet 尚未创建该命名空间,确认节点已加入集群 | |
x509: certificate signed by unknown authority | 私有仓库证书不受信,把 CA 放到 /etc/containerd/certs.d/<host>/ca.crt | |
failed to pull image: not found | 镜像名或 tag 错误,先 nerdctl search 或核对仓库路径 | |
no such file or directory /var/run/docker.sock | 误用了 docker 命令;nerdctl 不依赖 docker.sock | |
rootless 模式下 socket 在 $XDG_RUNTIME_DIR/containerd-rootless/ | 用 nerdctl 的 rootless 命令或显式 --address 指定 | |
failed to setup network namespace / CNI | CNI 插件缺失或配置损坏:检查 /etc/cni/net.d 与插件二进制 | |
port is already allocated | 宿主机端口被占用,用 ss -lntp 查占用进程 | |
nerdctl build 报 buildkit 不可用 | 需安装并启动 buildkitd,或改用 buildctl 构建 | |
nerdctl ps 看不到容器 | 命名空间不一致:加 -n k8s.io 或检查 nerdctl.toml 默认值 | |
ctr 与 nerdctl 的区别 | ctr 更底层难用,nerdctl 兼容 docker 习惯,日常优先 nerdctl | |
nerdctl events 观察运行时事件 | 容器频繁重启时可用于定位时序问题 |
运维常用组合
nerdctl run -d --name web -p 8080:80 -v /data/web:/usr/share/nginx/html nginx:1.25nerdctl build -t registry.example.com/app:v1 . → nerdctl login → nerdctl pushnerdctl -n k8s.io ps -a → nerdctl -n k8s.io logs <id> → nerdctl -n k8s.io exec -it <id> shnerdctl save -o app.tar app:v1 → scp → nerdctl load -i app.tarnerdctl system df → nerdctl image prune -a → nerdctl system prunenerdctl compose config → nerdctl compose up -d → nerdctl compose logs -f常见问题排查
1. 看不到 K8s 容器
K8s 使用 k8s.io 命名空间:nerdctl -n k8s.io ps -a,或在 nerdctl.toml 中固定默认命名空间
2. 构建报 buildkit 不可用
nerdctl build 依赖 BuildKit:安装 buildkit 并启动 buildkitd,rootless 需部署用户服务
3. 拉取镜像证书错误
把 CA 放到 /etc/containerd/certs.d/<registry>/ca.crt,或配置 insecure registry 后重启 containerd
4. 端口映射不生效
确认 CNI 正常且未用 --net host;用 nerdctl port 与 ss -lntp 双向核对
5. 磁盘增长过快
nerdctl system df 看占用来源,用 image prune / system prune 清理,并设置定期回收
6. 与 crictl 结果不一致
crictl 走 CRI 接口,nerdctl 走 containerd 原生 API,默认命名空间不同导致视角差异
相关工具
Linux命令速查
文件、文本、权限、进程、网络、磁盘、systemd与防火墙等 Linux 常用命令速查手册
Docker命令速查
镜像、容器、网络、数据卷、Compose、Swarm、清理与排障等 Docker 常用命令速查手册
Nginx命令速查
服务管理、配置指令、反向代理、HTTPS、限流缓存、日志排查等 Nginx 常用命令速查手册
K8S命令速查
集群上下文、Pod调试、工作负载、Service与Ingress、存储、权限、排障等 kubectl 常用命令速查手册
Windows CMD命令速查
文件目录、网络诊断、进程服务、系统信息、用户权限、注册表、批处理等 Windows CMD 常用命令速查手册
systemctl服务管理速查
服务启停、开机自启、unit文件编写、日志查看、定时器、依赖分析与排障等 systemctl 命令速查手册
关于nerdctl命令速查
在线 nerdctl 命令速查手册,按安装版本与全局参数、运行容器、容器查看与管理、镜像管理、镜像构建(BuildKit)、Compose 编排、网络管理(CNI)、Kubernetes 场景、存储清理与磁盘、故障排查等 10 类场景整理 125+ 条常用命令,每条附中文说明与可直接复制的写法,支持关键词搜索、分类折叠和一键复制,打开网页即可查阅。涵盖 nerdctl version 与 info 与 --address 与 --namespace k8s.io 与 --debug、/etc/nerdctl/nerdctl.toml 配置与 completion、run 的 -d/-it/--rm/-v/-w/-e/--network/--ip/-p/--net host/--restart/--cpus/--memory/--privileged/--platform/--pull/--label/--entrypoint、create/start/stop/restart、ps 与 -a 与 -q 与 --format 模板、inspect 与 jq、logs 的 -f/--tail/--since/--timestamps、exec -it、stats/top/port、rm -f 与 container prune 与 commit 与 pause、images 与 --digests 与 --format、pull 与 --platform、login/logout/tag/push/rmi/image prune -a、save/load/history、build 的 -t/-f/--build-arg/--target/--no-cache/--progress/--secret/--ssh/--platform --push 与 buildkitd 与 buildctl、compose up/down/ps/logs/exec/build/config 与 project-name、network ls/create/inspect/rm 与 --net none/host 与 --dns 与 /etc/cni/net.d、k8s.io 命名空间的 ps/images/logs/exec/inspect 与 crictl 对照、system df 与 system prune 与 volume 管理与 df -h /var/lib/containerd、failed to connect to containerd 与 permission denied 与 x509 与 CNI 与 buildkit 不可用 与端口占用与命名空间不一致等报错排查。适用于 containerd 环境下的容器与镜像运维、Kubernetes 节点容器调试、BuildKit 镜像构建、compose 本地编排与节点磁盘治理,以及运维与 DevOps 面试复习。
核心能力
- 涵盖 nerdctl version 与 info 与 --address 与 --namespace k8s.io 与 --debug、/etc/nerdctl/nerdctl.toml 配置与 completion、run 的 -d/-it/--rm/-v/-w/-e/--network/--ip/-p/--net host/--restart/--cpus/--memory/--privileged/--platform/--pull/--label/--entrypoint、create/start/stop/restart、ps 与 -a 与 -q 与 --format 模板、inspect 与 jq、logs 的 -f/--tail/--since/--timestamps、exec -it、stats/top/port、rm -f 与 container prune 与 commit 与 pause、images 与 --digests 与 --format、pull 与 --platform、login/logout/tag/push/rmi/image prune -a、save/load/history、build 的 -t/-f/--build-arg/--target/--no-cache/--progress/--secret/--ssh/--platform --push 与 buildkitd 与 buildctl、compose up/down/ps/logs/exec/build/config 与 project-name、network ls/create/inspect/rm 与 --net none/host 与 --dns 与 /etc/cni/net.d、k8s.io 命名空间的 ps/images/logs/exec/inspect 与 crictl 对照、system df 与 system prune 与 volume 管理与 df -h /var/lib/containerd、failed to connect to containerd 与 permission denied 与 x509 与 CNI 与 buildkit 不可用 与端口占用与命名空间不一致等报错排查
适用场景
适用于 containerd 环境下的容器与镜像运维、Kubernetes 节点容器调试、BuildKit 镜像构建、compose 本地编排与节点磁盘治理,以及运维与 DevOps 面试复习。nerdctl命令速查全程在浏览器中完成,无需安装插件,可放心用于日常办公与排障。
常见问题
- nerdctl命令速查是免费的吗?需要注册或安装吗?
- nerdctl命令速查完全免费,无需注册、无需下载安装任何软件,用浏览器打开网页即可直接使用,也不限制使用次数。
- nerdctl命令速查支持哪些功能?
- 涵盖 nerdctl version 与 info 与 --address 与 --namespace k8s.io 与 --debug、/etc/nerdctl/nerdctl.toml 配置与 completion、run 的 -d/-it/--rm/-v/-w/-e/--network/--ip/-p/--net host/--restart/--cpus/--memory/--privileged/--platform/--pull/--label/--entrypoint、create/start/stop/restart、ps 与 -a 与 -q 与 --format 模板、inspect 与 jq、logs 的 -f/--tail/--since/--timestamps、exec -it、stats/top/port、rm -f 与 container prune 与 commit 与 pause、images 与 --digests 与 --format、pull 与 --platform、login/logout/tag/push/rmi/image prune -a、save/load/history、build 的 -t/-f/--build-arg/--target/--no-cache/--progress/--secret/--ssh/--platform --push 与 buildkitd 与 buildctl、compose up/down/ps/logs/exec/build/config 与 project-name、network ls/create/inspect/rm 与 --net none/host 与 --dns 与 /etc/cni/net.d、k8s.io 命名空间的 ps/images/logs/exec/inspect 与 crictl 对照、system df 与 system prune 与 volume 管理与 df -h /var/lib/containerd、failed to connect to containerd 与 permission denied 与 x509 与 CNI 与 buildkit 不可用 与端口占用与命名空间不一致等报错排查。
- nerdctl命令速查适合哪些场景使用?
- 适用于 containerd 环境下的容器与镜像运维、Kubernetes 节点容器调试、BuildKit 镜像构建、compose 本地编排与节点磁盘治理,以及运维与 DevOps 面试复习。