编程与软件工程github.com
Bocker:用 100 行 bash 实现的 Docker
Show HN: Bocker – Docker implemented in 100 lines of bash
2015 — 2024,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
Bocker 是用约 100 行 bash 实现的类 Docker 容器工具:它借助 btrfs 子卷充当镜像层,用 unshare 隔离 network、PID、mount 等命名空间并挂载私有 /proc,从而完成极简的容器创建与运行。作者的目标不是替代 Docker,而是证明容器的核心机制其实只依赖少数几个内核系统调用。
为什么经久不衰:它用不到百行脚本拆穿了容器的“魔法”,是理解 Linux 容器底层原理(命名空间、镜像分层)最直观的入门读物,且十几年来一直被人翻出来重读。
HN 评论精选
实测 96 行即可用,并指出用户命名空间、overlayfs、cgroups 等可扩展方向。
我在带 btrfs 卷的虚拟机里试了一下,简直是醍醐灌顶:只有 96 行,却相当可用,把“保持简单”推到了新高度。我用的 Wheezy LXC 镜像跑得还行,最小的 alpine 镜像则不太行,apk 抱怨它的数据库。如果能支持用户命名空间就好了,那样就能玩非特权容器;Overlayfs 也会是 btrfs 之外很妙的替代方案(内核 3.18 已有,4.04 支持多层 lower)。cgroups 支持也该列在清单上。cgroups 和命名空间都在内核里,网络、存储、分布式系统的 Linux 生态已经非常丰富,可能性无穷。现在 LXC、Docker、Rkt、Nspawn 之外又多了 Bocker 作伴。
tobbyb查看英文原文
Just playing with this in a VM with an attached btrfs volume, a complete revelation. 96 lines! And it's actually pretty functional. This takes keeping it simple to a whole new level. The Wheezy image I use with LXC worked well enough, the minimal alpine image not so well, apk complaining about its database. User name spaces support would be nice, then we can play with unprivileged containers. And Overlayfs would be a nifty alternative to btrfs, it's in kernel 3.18, and 4.04 adds support for multiple lower layers. But this btrfs implementation is cool too. Cgroups support will be somewhere on that list too. Cgroups and namespaces is in the kernel. General Linux ecosystem for networking, storage and distributed systems is already extensive. The possibilities are endless. So now LXC, Docker, Rkt and Nspawn have Bocker for company.
btrfs 子卷做镜像层是亮点;容器本质只是少数几个系统调用。
用 btrfs 子卷做镜像格式,这招很妙,和假想中的 systemd 打包系统思路相同(虽然我并不怎么热衷)。它 unshare 了 network、PID、mount 命名空间,并额外挂了一个私有的 /proc。我喜欢这类工具,因为它们是一次现实检验:Linux 容器的基础不过是几个关键系统调用,而且这些调用本身是有限制的。
vezzy-fnord查看英文原文
Using btrfs subvolumes as the image format, that's a nice touch. On the same road as the hypothetical systemd packaging system (not that I'm very enthusiastic about that). The network, PID and mount namespaces are the ones unshared, plus a private /proc. I like tools like this because they're reality checks on how the basics of Linux containers are just a few essential system calls, and particularly that they're limited.
补充了一个 bash 版 docker pull 的概念验证实现链接。
这里有一个用 bash 实现“docker pull”的概念验证(YMMV,我写完以后它大概已经坏了):https://gist.github.com/tlrobinson/c85dca269f4405ad4201
tlrobinson查看英文原文
Here's a proof-of-concept implementation of "docker pull" in bash (YMMV, I think it has broken since I wrote it): https://gist.github.com/tlrobinson/c85dca269f4405ad4201
同名项目撞车的趣事,并感叹 Docker 不再是黑魔法。
刚看到 HN 标题时我惊呆了——奇怪,那不是我写的工具吗(https://github.com/icy/bocker)。这位(不是我那个)bocker 的作者想法很棒,我要从他的脚本里学习。Docker 不再是魔法了!
anh79查看英文原文
When I first saw the HN title, I was so stunning. Weird, it's not my tool https://github.com/icy/bocker ;) The author of "bocker" (not my bocker) has a great idea. I would learn from the script. Docker is not magic anymore.!!
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选