TranslateProject/translated/tech/20210901 What are container runtimes.md
2021-09-07 08:41:36 +08:00

97 lines
5.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[#]: subject: "What are container runtimes?"
[#]: via: "https://opensource.com/article/21/9/container-runtimes"
[#]: author: "Nived V https://opensource.com/users/nivedv"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
什么是容器运行时?
======
深入了解容器运行时,你就可以理解容器环境是如何建立的。
![Ships at sea on the web][1]
在对[容器镜像][2]的检查中,我讨论了容器的基本原理,但现在是时候深入研究容器运行时了,这样你就可以了解容器环境是如何构建的。本文的部分信息摘自 Open Container Initiative (OCI)(容器的开放标准)的[官方文档][3],所以无论你的容器引擎如何,这些信息都是相关的。
### 容器运行机制
那么,当你运行 `podman run``docker run` 命令时,在后台到底发生了什么?这里为你提供一个逐步的概述:
1. 如果本地没有镜像,则从镜像注册处拉取镜像
2. 镜像被提取到一个写时拷贝的文件系统上,所有的容器层相互叠加以创建一个合并的文件系统
3. 准备一个容器挂载点
4. 从容器镜像中设置元数据,包括诸如覆盖 CMD、来自用户输入的 ENTRYPOINT、设置 SECCOMP 规则等设置,以确保容器按预期运行
5. 提醒内核为该容器分配某种隔离,如进程、网络和文件系统(命名空间)
6. 内核还被提醒为这个容器分配一些资源限制,如 CPU 或内存限制cgroups
7. 一个系统调用syscall被传递给内核以启动容器
8. 设置 SELinux/AppArmor
容器运行时负责上述所有的工作。当我们想到容器运行时,想到的可能是 runc、lxc、containerd、rkt、cri-o 等等。嗯,你没有错。这些都是容器引擎和容器运行时,每一种都是为不同的情况建立的。
_容器运行时_更侧重于运行容器为容器设置命名空间和 cgroups也被称为底层容器运行时。高层的容器运行时或容器引擎专注于格式、解包、管理和镜像共享。它们还为开发者提供 API。
### Open Container Initiative OCI
Open Container InitiativeOCI是一个 Linux 基金会项目。其目的是设计某些开放标准或围绕如何与容器运行时和容器镜像格式工作的结构。它是由 Docker、rkt、CoreOS 和其他行业领导者于 2015 年 6 月建立的。
它使用两个规范来做这件事:
#### 1\. 镜像规范image-spec
该规范的目标是创建可互操作的工具,用于构建、传输和准备运行的容器镜像。
该规范的高层组件包括:
* [Image Manifest][4] — 一个描述构成容器镜像的元素的文件
* [Image Index][5] — 镜像清单的注释索引
* [Image Layout][6] — 一个代表镜像内容的文件系统布局
* [Filesystem Layer][7] — 一个描述容器文件系统的变化集
* [Image Configuration][8] — 确定镜像层排序和配置的文件,适合转换成[运行时包][9]。
* [Conversion][10] — 解释应该如何进行转换的文件
* [Descriptor][11] — 一个描述被引用内容的类型、元数据和内容地址的参考资料
#### 2\. 运行时规范runtime-spec
该规范旨在定义容器的配置、执行环境和生命周期。config.json 文件为所有支持的平台提供了容器配置,并详细说明了能够创建容器的地方。执行环境与为容器的生命周期定义的通用操作一起被详细说明,以确保在容器内运行的应用在不同的运行时之间有一个一致的环境。
Linux 容器规范使用了各种内核功能包括命名空间、cgroups、capabilities、LSM 和文件系统监牢来实现该规范。
### 现在你知道了
容器运行时是由 OCI 规范管理的,以提供一致性和互操作性。许多人在使用容器时不需要了解它们是如何工作的,但当你需要排除故障或优化使用方法时,了解容器是一个宝贵的优势。
* * *
_本文基于 [techbeatly][12] 的文章并经授权改编。_
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/9/container-runtimes
作者:[Nived V][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/nivedv
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/kubernetes_containers_ship_lead.png?itok=9EUnSwci (Ships at sea on the web)
[2]: https://opensource.com/article/21/8/container-fundamentals-2
[3]: https://github.com/opencontainers
[4]: https://github.com/opencontainers/image-spec/blob/master/manifest.md
[5]: https://github.com/opencontainers/image-spec/blob/master/image-index.md
[6]: https://github.com/opencontainers/image-spec/blob/master/image-layout.md
[7]: https://github.com/opencontainers/image-spec/blob/master/layer.md
[8]: https://github.com/opencontainers/image-spec/blob/master/config.md
[9]: https://github.com/opencontainers/runtime-spec
[10]: https://github.com/opencontainers/image-spec/blob/master/conversion.md
[11]: https://github.com/opencontainers/image-spec/blob/master/descriptor.md
[12]: https://medium.com/techbeatly/container-runtimes-deep-dive-77eb0e511939