Linux containers in 500 lines of code

A deep dive into building Linux containers from scratch in just 500 lines of code. The author explores kernel features like namespaces and capabilities, highlighting security pitfalls such as user namespace privilege escalation. Includes code examples, discussions of distribution patches (Ubuntu, Debian, Arch), and practical demonstrations of container isolation.

If a (real) root user has had the SYS_CAP_ADMIN capability removed, but then creates a user namespace, this capability is restored for the (fake) root user.
  1. zoobab

    I discovered proot-distro build yesterday, which does not require a special kernel with network and pid namespaces, it could run on older machines that do not have those features, or as a unix user that don't have those permissions.

    https://pypi.org/project/proot-distro/

  2. smashed

    Coincidentally I mis-prompted claude code the other day while working on a toy project and failed to specify the project should be built on top of docker and not "like docker".

    It went on to waste all my tokens creating a specialized docker clone. Cool I guess.

  3. js2

    (2016). Previous submissions w/comments:

    https://news.ycombinator.com/item?id=30623372 (250 points | March 10, 2022 | 27 comments)

    https://news.ycombinator.com/item?id=22232705 (267 points | Feb 4, 2020 | 29 comments)

    https://news.ycombinator.com/item?id=15608435 (440 points | Nov 2, 2017 | 53 comments)

  4. setheron

    I have written https://fzakaria.com/2020/05/31/containers-from-first-princi... a while ago in similar vein.

  5. abidinberkay

    This was written in 2016. What would be different if you wrote it today? For example would cgroups v2 or newer seccomp features change that much?

More from this day

2026-10-05