Nerdctl Config 配置指南

在这里插入图片描述

1. 什么是 nerdctl?

nerdctl 是一个与 docker 命令兼容的容器运行时 CLI,基于 containerd,可以在没有 dockerd 的情况下运行容器。它适用于 Kubernetes 和轻量级容器环境,特别适合与 containerdnerdctl 结合使用的开发者和运维人员。

2. 配置文件位置

nerdctl 的默认配置文件路径如下:

  • Linux/macOS: ~/.config/nerdctl/nerdctl.toml
  • Windows: C:\Users\<用户名>\.config\nerdctl\nerdctl.toml

你可以手动创建 nerdctl.toml 来修改默认行为。

3. 配置项解析

3.1 运行时(runtime)配置

[default]
cni_path = "/opt/cni/bin"
cni_config_path = "/etc/cni/net.d"
  • cni_path:CNI 插件的可执行文件目录
  • cni_config_path:CNI 网络配置文件路径

3.2 容器镜像设置

[registry]
  mirrors = { "docker.io" = { endpoint = ["https://mirror.gcr.io"] } }
  • mirrors:配置加速镜像源,例如使用 GCR 代理 mirror.gcr.io

3.3 存储配置

[containerd]
snapshotter = "overlayfs"
  • snapshotter:设置存储后端(如 overlayfs, zfs, btrfs

3.4 nerdctl 命令别名

[alias]
  myrun = "run --rm -it"
  • alias:定义自定义命令别名,例如 nerdctl myrun ubuntu 相当于 nerdctl run --rm -it ubuntu

4. 使用 nerdctl config 命令

nerdctl config 提供了一些管理配置的子命令:

  • nerdctl config info:查看当前 nerdctl 配置
  • nerdctl config show-defaults:显示默认配置
  • nerdctl config edit:编辑配置文件

示例:

nerdctl config info

5. 配置示例:使用 nerdctl 运行私有仓库镜像

如果你使用的是私有镜像仓库(如 harbor.example.com),可以在 nerdctl.toml 中添加:

[registry]
  [registry."harbor.example.com"]
    http = true
    insecure = true

然后执行 nerdctl pull harbor.example.com/my-image:v1 以拉取镜像。

6. kubernetes默认 nerdctl 配置

  • Rootful mode: /etc/nerdctl/nerdctl.toml
  • Rootless mode: ~/.config/nerdctl/nerdctl.toml
$ vim /etc/nerdctl/nerdctl.toml 
debug             = false
debug_full        = false
address           = "unix:///var/run/containerd/containerd.sock"
namespace         = "k8s.io"
snapshotter       = "overlayfs"
cni_path          = "/opt/cni/bin"
cni_netconfpath   = "/etc/cni/net.d"
cgroup_manager    = "systemd"
hosts_dir         = ["/etc/containerd/certs.d"]
insecure_registry = true 

7. 结论

nerdctl 是一个强大且轻量的 containerd CLI,支持与 docker 类似的操作方式。通过配置 nerdctl.toml,可以优化网络、存储和镜像管理,使其更适合你的工作流。如果你正在使用 Kubernetes 或者希望摆脱 dockerdnerdctl 绝对值得一试!

参考:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ghostwritten

口渴,请赏一杯下午茶吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值