# runc

**runc** 是一个命令行工具，用于在 Linux 上按照开放容器倡议（OCI）规范创建并运行容器。<sup>[1](https://github.com/opencontainers/runc)</sup> 它是真正创建容器的底层组件：给定一个 OCI 包——即一个包含容器根文件系统和 config.json 文件的目录——runc 会配置命名空间、cgroups（[Linux 内核](https://www.edgepedia.org/zh/linux-kernel)中用于限制进程资源使用的功能）、挂载点和安全设置，然后启动容器进程。<sup>[1](https://github.com/opencontainers/runc)</sup><sup> • </sup><sup>[2](https://blog.gntech.me/posts/2026-06-16-container-runtimes-runc-vs-crun-docker/)</sup> Docker、containerd、Podman 和 CRI-O 等上层工具会调用 runc（或兼容的运行时）来完成这项工作；runc 本身不管理镜像，也不包含长期运行的守护进程逻辑。<sup>[2](https://blog.gntech.me/posts/2026-06-16-container-runtimes-runc-vs-crun-docker/)</sup>

| 关键事实 | 详情 |
|---|---|
| 用途 | 按照 OCI 规范在 Linux 上创建并运行容器的命令行工具<sup>[1](https://github.com/opencontainers/runc)</sup> |
| 输入格式 | 容器必须以 OCI 包的形式提供（根文件系统加 config.json）<sup>[3](https://github.com/opencontainers/runc/blob/main/README.md)</sup> |
| 平台 | 仅支持 Linux；构建需要 Go 以及 libseccomp 等库<sup>[1](https://github.com/opencontainers/runc)</sup> |
| 在栈中的角色 | Docker 默认附带的运行时；由 containerd 通过 io.containerd.runc.v2 shim 调用<sup>[2](https://blog.gntech.me/posts/2026-06-16-container-runtimes-runc-vs-crun-docker/)</sup><sup> • </sup><sup>[4](https://containerd.org/docs/2.4/runtime-v2/)</sup> |
| 内存占用 | 每个实例约 15 MB RSS，而基于 C 的 crun 约为 5 MB<sup>[2](https://blog.gntech.me/posts/2026-06-16-container-runtimes-runc-vs-crun-docker/)</sup> |
| 安全审查 | 由 Cure53 进行第三方安全审计；发布版本使用 runc.keyring 中的密钥签名<sup>[1](https://github.com/opencontainers/runc)</sup> |
| 2025 年漏洞 | CVE-2025-31133（CVSS 7.3）、CVE-2025-52565 和 CVE-2025-52881，串联利用后可获得容器宿主机的管理员权限<sup>[5](https://www.techradar.com/pro/security/some-docker-containers-may-not-be-as-secure-as-they-like-experts-warn)</sup> |

## runc 的职责

runc 实现了 OCI 运行时规范，该标准定义了如何从包创建容器，以及容器的生命周期操作如何执行。<sup>[1](https://github.com/opencontainers/runc)</sup><sup> • </sup><sup>[3](https://github.com/opencontainers/runc/blob/main/README.md)</sup> 项目 README 描述了两种启动容器的方式：直接启动，或通过规范中的生命周期操作启动。<sup>[3](https://github.com/opencontainers/runc/blob/main/README.md)</sup> 当 runc 运行容器时，它会从包生成容器：创建 cgroups 树、应用命名空间、设置根文件系统、运行 seccomp 过滤器，并执行容器进程。<sup>[2](https://blog.gntech.me/posts/2026-06-16-container-runtimes-runc-vs-crun-docker/)</sup>

由于行为由 OCI 规范定义，crun（用 C 编写）和 youki（用 Rust 编写）等替代运行时可以在使用相同包和相同调用工具的情况下替换 runc。<sup>[2](https://blog.gntech.me/posts/2026-06-16-container-runtimes-runc-vs-crun-docker/)</sup><sup> • </sup><sup>[6](https://www.sumguy.com/crun-runc-youki-oci-runtimes/)</sup>

## 在容器栈中的位置

一次典型的容器启动涉及多个层次。Docker 与 containerd 通信，containerd 调用更低层的工具，该工具配置命名空间、cgroups 以及使容器成为容器的 pivot root；这个工具就是 OCI 运行时，通常是 runc。<sup>[6](https://www.sumguy.com/crun-runc-youki-oci-runtimes/)</sup> 在 containerd 中，`io.containerd.runc.v2` shim 调用符合 OCI 的运行时引擎（如 runc），属于同一 [Kubernetes](https://www.edgepedia.org/zh/kubernetes) pod 的容器由单个 shim 处理，并按 CRI 插件设置的 `io.kubernetes.cri.sandbox-id` 标签分组。<sup>[4](https://containerd.org/docs/2.4/runtime-v2/)</sup>

在 Kubernetes 中，containerd 的 CRI 插件处理来自 kubelet 的 CRI 服务请求，并利用 containerd 内部机制管理完整的容器生命周期和镜像，pod 网络通过 CNI 配置；runc 位于底层，是实际启动每个容器的引擎。<sup>[7](https://containerd.io/docs/main/cri/architecture/)</sup> Kubernetes 文档展示了 runc 运行时的 containerd 配置，包括 `SystemdCgroup = true` 选项，并指出使用 cgroup v2 时推荐 systemd cgroup 驱动。<sup>[8](https://kubernetes.io/docs/setup/production-environment/container-runtimes/)</sup>

## 实现与性能

runc 用 Go 编写。根据 crun 项目的 README，用 Go 编写的 runc 必须重新执行自身，并依赖一个 C 模块在容器进程启动前配置环境，因为 Go 无法直接进行某些所需的系统调用；crun 用 C 实现，跳过了这一重新执行步骤，README 将 crun 更快的速度和更小的内存占用归因于这一差异。<sup>[9](https://hysenlabs.com/projects/containers-crun)</sup> 同一 README 的性能部分报告，顺序运行 100 个容器（每个运行 /bin/true）时，crun 耗时 0:01.69，runc 耗时 0:3.34，表格将这一差异表示为 -49.4%。<sup>[9](https://hysenlabs.com/projects/containers-crun)</sup> 另一项对比显示，runc 每个实例的内存占用约为 15 MB RSS，而 crun 约为 5 MB。<sup>[2](https://blog.gntech.me/posts/2026-06-16-container-runtimes-runc-vs-crun-docker/)</sup>

这些差异在大量容器频繁启动或内存紧张的场景中最为重要；面向家庭实验室用户的对比建议将 crun 作为默认选择，同时保留 runc 用于兼容性重要的场合。<sup>[2](https://blog.gntech.me/posts/2026-06-16-container-runtimes-runc-vs-crun-docker/)</sup> runc 仍然是 Docker 默认附带的运行时，也是 Docker、containerd 和 CRI-O 默认封装的运行时。<sup>[2](https://blog.gntech.me/posts/2026-06-16-container-runtimes-runc-vs-crun-docker/)</sup><sup> • </sup><sup>[10](https://www.safeguard.sh/resources/blog/container-runtime-runc-vs-crun-vs-gvisor-2026)</sup>

## 安全

该项目发布了安全报告与披露流程，并由 Cure53 进行了第三方安全审计。<sup>[1](https://github.com/opencontainers/runc)</sup> 由于 runc 以宿主机级别权限运行来配置容器，其中的缺陷可能很严重。2025 年 11 月，安全研究员 Aleksa Sarai 披露了三个高危漏洞：CVE-2025-31133、CVE-2025-52565 和 CVE-2025-52881。CVE-2025-31133 的严重性评分为 7.3（满分 10），源于 runc 未执行足够的验证，导致信息泄露、拒绝服务甚至容器逃逸；CVE-2025-52565 是另一个检查不足的缺陷，导致拒绝服务。三个漏洞串联利用后，可获得底层容器宿主机的管理员权限。当时的报道指出没有证据表明这些漏洞已被滥用。<sup>[5](https://www.techradar.com/pro/security/some-docker-containers-may-not-be-as-secure-as-they-like-experts-warn)</sup>

## 构建与发布

runc 仅支持 Linux。构建它需要 Go（最低版本见 go.mod 头部）以及一些工具和库；在 Ubuntu 或 Debian 上，文档记录的依赖安装包括 make、gcc、linux-libc-dev、libseccomp-dev、pkg-config 和 git。<sup>[1](https://github.com/opencontainers/runc)</sup> 正式发布版本发布在项目的发布页面，所有发布版本均由仓库根目录 runc.keyring 文件中列出的密钥之一签名。<sup>[1](https://github.com/opencontainers/runc)</sup>

## References

1. [opencontainers/runc, GitHub repository README](https://github.com/opencontainers/runc)
2. [Container Runtimes: runc vs crun for Docker Performance in Homelab, GnTech Blog](https://blog.gntech.me/posts/2026-06-16-container-runtimes-runc-vs-crun-docker/)
3. [runc/README.md at main, GitHub](https://github.com/opencontainers/runc/blob/main/README.md)
4. [containerd docs – Runtime V2](https://containerd.org/docs/2.4/runtime-v2/)
5. [Some Docker containers may not be as secure as they like, experts warn, TechRadar](https://www.techradar.com/pro/security/some-docker-containers-may-not-be-as-secure-as-they-like-experts-warn)
6. [crun vs runc vs youki: OCI Runtimes Compared, SumGuy's Ramblings](https://www.sumguy.com/crun-runc-youki-oci-runtimes/)
7. [containerd docs – Architecture of the CRI Plugin](https://containerd.io/docs/main/cri/architecture/)
8. [Container Runtimes, Kubernetes documentation](https://kubernetes.io/docs/setup/production-environment/container-runtimes/)
9. [crun: OCI runtime in C, Podman crun setup, Hysen Labs](https://hysenlabs.com/projects/containers-crun)
10. [Container Runtime Showdown: runc vs crun vs gVisor in 2026, safeguard.sh](https://www.safeguard.sh/resources/blog/container-runtime-runc-vs-crun-vs-gvisor-2026)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Named software products and platforms › Cloud, virtualization, and containers › Container tools and runtimes

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/runc

English original: https://www.edgepedia.org/runc
