系统与基础设施blog.lizzie.io编辑精选
用 500 行代码理解 Linux 容器
Linux containers in 500 lines of code
2017 — 2022,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇文章以文学编程的方式,用约 500 行代码实现一个极简 Linux 容器,并逐段解释背后的系统调用与隔离机制。它把 Docker 之类工具遮住的底层细节摊开,配以大量上下文说明,适合想真正理解容器原理的读者。
为什么经久不衰:它把“容器”从 Docker 的黑盒还原成可读代码和系统调用,篇幅小、解释足,多年后仍是理解容器底层的好入口。
HN 评论精选
建议 capabilities 采用白名单而非黑名单,避免遗漏。
root capabilities 那一节令人担忧。与其试图穷举列出每个需要丢弃的 capability,代码是不是应该反过来只列出允许的 capability,然后清掉其余所有?这样更能防止漏掉现有 capability,也能防范未来内核新增的 capability。
joosters查看英文原文
The root capabilities section is worrying. Instead of trying to exhaustively list every capability that needs to be dropped, shouldn't the code instead just list the capabilities that are allowed, and clear all the others? This would seem to better guard against accidentally missing existing capabilities, and also protect against newer capabilities that might be added in a future kernel.
称赞文学编程形式,解释篇幅远超代码本身。
多好的一篇文学编程作品!我刚把它打印出来,它确实为那 500 行代码配了 100 页的解释和背景。干得漂亮!
szemet查看英文原文
What a fine piece of literate programming! I've just printed it out, and it literally contains 100 page of explanation and context for that 500 lines of code. Great work!
分享 Guix 的 Scheme 容器实现,强调注释和文档有助理解。
既然其他人在分享轻量容器实现,我也来加一个。这个是用 Scheme 写的:http://git.savannah.gnu.org/cgit/guix.git/tree/gnu/build/linux-container.scm#n268 我认为其中的代码注释和文档字符串足够多,能帮助揭开容器底层运作原理。
davexunit查看英文原文
Since others are sharing lightweight container implementations, I'll throw mine in. This one is written in Scheme: http://git.savannah.gnu.org/cgit/guix.git/tree/gnu/build/linux-container.scm#n268 I like to think that there are sufficient code comments and docstrings to help demystify what is going on under the hood with containers.
容器概念不复杂,但 syscall、基础工具和编排体验仍有改进空间。
Linux 容器并非火箭科学,但系统调用 API 令人困惑且很难用对(我觉得 pid namespace 尤其烦人),基础用户命令(unshare、ip netns……)用起来也挺痛苦,而用 Docker/Kubernetes 做编排又过于复杂和不透明。显然各个层面都有改进空间。
musicale查看英文原文
Linux containers aren't rocket science, but the system call API is confusing and hard to get right (I find pid namespaces particularly annoying), the basic user commands (unshare, ip netns...) are kind of a pain to use, and orchestration using Docker/Kubernetes is overly complex and opaque. There is clearly room for improvement at all levels.
历次讨论
同类还值得读
TTY 揭秘(2008)
The TTY demystified (2008)
经典文章深入剖析了 Unix/Linux 中 TTY 子系统的工作原理,包括线路规程、终端驱动、信号与控制字符等机制。
系统与基础设施上首页 11 次 · 2009–2025linusakesson.net编辑精选为什么 GNU grep 这么快
Why GNU grep is Fast
FreeBSD 邮件列表上一篇广为流传的帖子,解释 GNU grep 为什么快:核心在于 Boyer-Moore 字符串搜索算法配合精心优化的内部循环和 I/O,让程序在搜索时“…
系统与基础设施上首页 9 次 · 2010–2022lists.freebsd.orgXplain:为普通人讲解 X11
Xplain – Explaining X11 for the rest of us
《Xplain》是作者(HN 用户 Jasper_)写的一系列 X11 长文,用他在浏览器中重建的 X11 绘图模型做交互演示,讲解 X11 的绘图模型与窗口系统设计。
系统与基础设施上首页 6 次 · 2013–2020magcius.github.io编辑精选旋风教程:为 Linux 创建极小 ELF 可执行文件(1999)
A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux (1999)
breadbox 写于 1999 年的经典教程,主题是如何为 Linux 手工构造并裁剪出体积极小的 ELF 可执行文件。
系统与基础设施上首页 6 次 · 2007–2025muppetlabs.comPostgreSQL 内部原理
The internals of PostgreSQL
《The Internals of PostgreSQL》是一本免费在线书籍,系统讲解 PostgreSQL 的内部实现,包括查询处理、并发控制、WAL、缓冲区管理等核心机制。
系统与基础设施上首页 5 次 · 2017–2025interdb.jp编辑精选