当前位置: 首页 > news >正文

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

目录

      • 核心特点
      • 基础命令示例
      • 与 Kubernetes 协同
      • 安装方法
      • 配置示例
        • 完整参考:
        • Properties

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
http://www.dtcms.com/a/283014.html

相关文章:

  • 17.图像金字塔采样(放大,缩小处理)拉普拉斯金字塔
  • 闰年的历史由来与C语言实现详解
  • 7.16 拓扑排序 | 欧拉回路 |链表排序 前缀和
  • Vue在线预览Excel和Docx格式文件
  • Redis学习其一
  • Python学习之路(十三)-常用函数的使用,及优化
  • Redis读写策略深度解析:高并发场景下的缓存兵法
  • python基础语法9,用os库实现系统操作并用sys库实现文件操作(简单易上手的python语法教学)
  • 猫眼娱乐IOS开发一面手撕算法
  • 嵌入式学习笔记--MCU阶段--DAY06DHT11练习
  • AR智能巡检:电力行业数字化转型的“加速器”
  • 基于Llama的RAG 3种模型配置方法
  • 51c自动驾驶~合集7
  • 基于C#开发solidworks图库中文件(SLDPRT,SLDASM,SLDDRW等)转换为HTML和PDF,提供批量和实时转换
  • AI产品经理面试宝典第28天:自动驾驶与智慧交通融合面试题与答法
  • 自动驾驶激光3D点云处理系统性阐述及Open3D库函数应用
  • MR 处于 WIP 状态的WIP是什么
  • 小模型的价值重估:从“缩水版DeepSeek”到AI系统的基础执行单元20250716
  • Linux 挂载新磁盘导致原文件被隐藏解决方案
  • 【代码】Matlab鸟瞰图函数
  • sqli-labs靶场通关笔记:第23关 注释符过滤
  • 叉车机器人如何实现托盘精准定位?这项核心技术的原理和应用是什么?
  • 静默的田野守护者:Deepoc具身智能如何让除草机器人读懂大地密语
  • Mybatis08-使用pageHelper
  • 本地 AI 问答机器人搭建项目(Ollama + Qwen-7B + LangChain + FastAPI)
  • AI对话聊天与桌宠工具调研报告
  • 【案例分享】基于FastCAE-Acoustics软件对车门进行噪声预测
  • 移动平板电脑安全管控方案
  • 祥云系统开源云商城程序全开源版 个人程序云商城(源码下载)
  • 前端学习7:CSS过渡与动画--补间动画 (Transition) vs 关键帧动画 (Animation)