by brainzap · 1w ago · 0 comments
It's a solution to something that shouldn't be a problem in the first place, if the OS was designed better.
Operating systems we use today were designed in an era when security and isolation were an afterthought at best. Plenty of security features have been bolted on over time to enable what we now call containerization, such as cgroups, namespaces, seccomp-bpf, capabilities, etc. But each part was added separately with its own API and tricky edge cases. Docker is needed as a midlayer to package them up into something a normal person can use.
If, however, the OS was designed from the ground up so that every process is only handed exactly the resources it needs (files, network endpoints, device handles, ...) as capabilities, every application would simply run sandboxed by default. Instead of taking away / altering permissions from a process that starts out with all permissions, we'd only add the exact capabilities it needs via a unified and clean system API. Capabilities handle not only permissions but also make namespacing practically free. The only Docker-like thing we might still need is a way to package and distribute images, but that's a much simpler problem to solve.
This is not a new idea, Fuchsia basically implements this. seL4 provides the necessary foundation as well. Plan 9 at least has per-process namespaces, which get us most of the way there.
Consider macOS. The closest equivalent to a container is the bundle. Bundles are much better that containers in several ways:
1. They're much simpler. Just directories with a special structure that's recognized by the OS.
2. They're much more efficient. A bundle ships only the program and any dependencies that sit outside the OS, but Apple invests so much in developing frameworks and in backwards compatibility, that a huge range of apps can be built that require no additional dependencies whatsoever. It's common for sophisticated Mac GUI apps to have bundle sizes in the tens of megabytes, whereas Docker images often require pulling gigabytes. Bundles are typically updated using tight per-file delta update schemes like Sparkle or the App Store, whereas Docker's delta update support is minimal (whatever was easy to implement at the time, basically).
3. They're decentralized. There is no de-facto reliance on a collection of hubs which charge lots of money for bandwidth (some companies block Docker Hub for this reason). Nor is bundle identity allocated by registries - you can create a bundle with a stable identity that survives upgrades even if you pass the bundles around on SD cards.
4. They're actually more "UNIX philosophy". You can move them around and organize them in the same way as any other kind of file or directory. You can "cd" into them from the shell, or synchronize them with Google Drive. There is no need for special servers, repositories, pulls or pushes.
5. They have much better support for sandboxing.
6. They share the same namespaces as the host, so there are no confusing path remappings going on. Despite that, sandboxed app get private areas of the user's home directory that are protected from other apps.
The underlying architecture here isn't perfect; bundles evolved over a period of decades and there's no rigid spec for the internal directory layout. The OS relies on collections of heuristics to identify bundles in a few cases. But it's architecturally much cleaner than Docker.
as for the list of points:
1. sure, though an OCI image can be exported to a flat bundle too if you don't care about layer efficiency
2. that's one of the things you don't want with docker containers. Nothing is stopping you from `-v /usr/lib:/usr/lib -v /bin:/bin` but you don't want that. Arguments about how much Apple or Windows puts into backward compatibility are moot once a minor breaking change is pushed to these machines without you knowing about it or if you want to explicitly have a different version of a platform library or dependency for one particular container
3. OCI registries are decentralized. The reliance on docker hub is just a convenance. It's like git is decentralized, the fact that everyone relies on GitHub is their own issue. If a DmgHub came up tomorrow where everyone uploads their dmg to it, and it became the socially acceptable place to always fetch dmgs from, did bundles become suddenly centralized and we need a different OS primitive to be decentralized again? the reason they are decentralized today is because no one cared to centralize them (except Apple's App Store of course)
4. You can do that with OCI images too
5. Nope. What's the bundle's equivalent of seccomp profiles? user-mode kernel/runsc? kata (VT-x or AMD-V) isolation?
6. That's a downside not an upside. You can put all your OCI files under /app, and mount the rest of the host mount namespace too. No one does that because they don't want to, not because it's not possible.
We're so far away from that its absurd. Yet an O/S designed from the ground-up to be simple (on modern hardware), would make that very simple.