← All projectsProblem statement Solution Architecture Key features Challenges Lessons learned
2026
mydocker (Container Runtime from Scratch)
A minimal Docker-like container runtime built from scratch in Go, with no external container libraries: namespaces, cgroups v2, pivot_root, and hand-built veth networking.
Docker feels like magic until you ask what actually isolates a container from its host. I wanted to understand the Linux primitives underneath it rather than just consuming the CLI.
A minimal container runtime written in Go that reimplements Docker's core isolation model directly on top of Linux kernel features (namespaces, cgroups, and networking), with no external containerization libraries.
The runtime re-executes itself via /proc/self/exe: the parent forks a child with PID, UTS, mount, and network clone flags, then creates a veth pair, moves one end into the child's namespace, and signals it over a pipe. The child joins a cgroup with memory and process limits, sets its hostname, configures its side of the network (10.0.0.2/24, default route via the host), pivot_roots into a minimal Alpine root filesystem, mounts a fresh /proc, and execs the requested command. The host side handles veth setup and cleanup; internet access uses a one-time NAT/iptables rule.
- Process isolation via PID namespaces, so the container sees itself as PID 1
- Hostname isolation through UTS namespaces
- Filesystem isolation via mount namespaces and pivot_root, with a fresh /proc and the old root detached
- Resource limits enforced with cgroups v2, configurable per run (--memory, --pids)
- Network namespace with automated veth pair setup and cleanup, and internet access via NAT/iptables
Getting namespace, cgroup, network, and pivot_root setup to happen in the right order without leaking host state, and syncing parent and child over a pipe so the veth is attached before the container configures it. pivot_root first failed with EINVAL, which I traced to os.UserHomeDir() resolving to /root under sudo rather than a WSL2 limitation, and fixed by using an absolute rootfs path.
Docker is mostly a thin, well-designed layer over primitives the kernel already provides. Building the isolation by hand made concepts like namespaces and cgroups concrete instead of abstract buzzwords.