阅读 OCI Runtime config.json:bundle 与进程设置
OCI Runtime Specification 定义本地 bundle 和 runtime 生命周期。了解 config.json 的关键字段,以及 create 准备环境、start 启动进程的区别。
阅读 OCI Runtime config.json:bundle 与进程设置
OCI Runtime Specification 定义容器的运行配置和本地生命周期。bundle 通常包含 config.json 和根文件系统。create 准备所请求的环境;只有 start 才会运行 process 中描述的应用。因此容器处于 created 状态但没有活动进程,可能是正常情况。
容器 runtime 指南说明 containerd、runc 等层次,containerd 指南介绍 Kubernetes 节点。本文聚焦阅读 OCI bundle。
OCI bundle 包含什么?
标准 bundle 是本地目录,根目录中有 config.json 和 root.path 指向的文件系统。rootfs 是常见名称,不是强制要求。路径必须相对于 bundle 可解析,目录也必须存在。
先检查哪些字段?
ociVersion 表示 bundle 遵循的规范版本;JSON 有效不代表 runtime 支持该版本或所有字段。root.path 指定根文件系统,在 POSIX/Linux 中可以是 bundle 相对路径。root.readonly 为 true 时,容器内该文件系统只读。
process.args 描述可执行程序和参数。在 Linux/POSIX 中,如果提供数组,至少要有一个条目,第一项指定程序;create 不会运行它。process.cwd 必须是根文件系统内有效的绝对路径。process.env 将 PORT=8080 等值传给进程;机密信息应单独安全管理。
mounts 添加额外挂载。destination 是容器内路径,按数组顺序应用;检查路径重叠和选项效果。linux.namespaces 描述 PID、网络、mount 等 Linux 隔离边界;支持与默认值取决于 runtime 和内核。
Windows、Solaris、FreeBSD 的字段和路径规则不同,不要原样照搬 Linux 设置。配置只是传给 runtime 的输入,不能证明安全策略或应用兼容性正确。
create 与 start 有何不同?
OCI 操作定义行为,不规定某个 CLI 的语法。给定 bundle 和 ID,create 创建环境并进入 created,但不会运行用户程序。之后修改 config.json 不会影响已创建的容器。start 才启动 process,状态变为 running;进程退出或 kill 后变为 stopped。delete 清理 create 阶段创建的资源,不应删除外部资源。
runtime 状态包含 id、status 和 bundle 路径等字段;它不同于 Kubernetes Pod Ready 状态。
如何区分配置和启动故障?
create 失败时检查 runtime 是否支持 ociVersion、root.path 是否存在、mount 路径与选项,以及 namespace 和权限是否可用。created 状态没有进程,可能只是尚未 start。start 失败时检查 process、可执行文件是否在根文件系统内、cwd 是否为有效绝对路径,以及库、权限和平台是否匹配。
修改 bundle 不会更新已创建容器。使用上层管理器文档化的重建/重启流程,手动更改受管理 bundle 前先确认恢复和回滚方法。
总结
OCI Runtime 是 bundle 配置和本地容器生命周期的契约,不是从 registry 传输镜像的规范。create 准备环境,start 执行程序。应分阶段诊断。
参考资料
[OCI Runtime Specification: Filesystem Bundle](https://github.com/opencontainers/runtime-spec/blob/main/bundle.md)
[OCI Runtime Specification: Configuration](https://github.com/opencontainers/runtime-spec/blob/main/config.md)
[OCI Runtime Specification: Lifecycle and State](https://github.com/opencontainers/runtime-spec/blob/main/runtime.md)
[OCI Runtime Specification v1.3.0](https://github.com/opencontainers/runtime-spec/releases/tag/v1.3.0)
OCI 文档及 v1.3.0 于 2026-11-23 查阅。内容仅作说明,未用 runtime 验证或执行。字段和操作流程因实现、版本、平台而异。