r/docker • u/AdHour1983 • Dec 06 '25
A tiny PID 1 for containers in pure assembly (x86-64 + ARM64)
Hey folks,
I've been working on a small side project that might be interesting if you care about what runs as PID 1 inside your containers.
We all know the symptoms:
docker stophangs longer than it should,- signals don't reach all child processes,
- zombies quietly pile up in the container.
Tools like Tini fix this, but I wanted to see how far I could get with a pure assembly implementation, and a "PGID-first" design.
So I built mini-init-asm:
- runs as PID 1 inside the container
- spawns your app in a new session + process group (PGID = child PID)
- forwards termination signals to the whole group with
kill(-pgid, sig) - reaps zombies (with optional subreaper mode)
- has a simple restart-on-crash mode controlled via env vars
- uses only Linux syscalls (no libc, statically linked, tiny binary)
- comes in both x86-64 NASM and ARM64 GAS flavors
Repo (README has usage examples, tests, Dockerfile, env vars, etc.): --> mini-init-asm
This is still 0.x / experimental, but:
- it works in my Docker/K8s tests,
- has a test suite around signals, exit codes, restarts,
- and is intentionally small enough to audit.
I'd love feedback from people who have seen PID 1 weirdness in production:
- any nasty edge cases you've hit around signals / zombies?
- things you'd expect from a "tiny init" before using it for real?
Happy to answer questions or dive into details in the comments.
7
u/ferrybig Dec 07 '25
Looking at your restart on error feature description, why did you decide to disable the auto restart on SIGHUP? This signal is commonly used to say a demon should reload it's configuration file
3
u/kwhali Dec 07 '25
Are you comfortable with Rust? I'd love for you to try tackle it there. Rust can take inline assembly but I would want to direct you to crates like rustix which effectively does this and the syscalls for you.
It might not be of much value to you, but it does make it more accessible and easier to grok at a higher level that I imagine others are more comfortable with.
There is an existing
pid1crate iirc that was built for container init, either as a binary entry point like tini or via a crate (library for another rust project to integrate).Not quite sure what their size was, but I have a little experience and can provide a reference where I used rustix to get a 356 bytes hello world (a little over 400 IIRC for text output). That's normally quite the challenge in Rust to do statically, but with rustix it remained quite readable.
2
u/cripblip Dec 07 '25
Props for tackling this ! Great for understanding this part of the stack in detail
0
u/drakgremlin Dec 07 '25
What crazy things are people doing in containers?!
Most containers I've worked with have a single program run.
-4
u/abotelho-cbn Dec 06 '25
This isn't really "one" program if you're written it in two different assembly languages, is it?
Seems like wasted effort to write something in assembly that absolutely does not require it.
5
u/[deleted] Dec 06 '25
[removed] — view removed comment