Vortex is a lightweight Linux container runtime written in C++ that demonstrates the core principles of containerization: namespaces, control groups, and filesystem isolation.
- Namespace Isolation:
PID: Isolated process tree (container sees itself as PID 1).UTS: Isolated hostname.Mount: Isolated filesystem mounts.Network: Isolated network stack (with loopback interface).
- Filesystem Isolation:
- Uses
pivot_rootto securely change the root filesystem. - Automatically mounts
/procfor process visibility.
- Uses
- Resource Control:
- Uses
Cgroups v2to limit memory usage (default 100MB).
- Uses
- Alpine Linux Support:
- Designed to run with minimalist rootfs like Alpine.
Vortex works by following these steps:
- Clone: Uses the
clone()syscall with specific flags (CLONE_NEWPID,CLONE_NEWUTS, etc.) to create a new process in new namespaces. - Cgroups: The parent process creates a cgroup in
/sys/fs/cgroup/vortexand adds the child PID to it, applying resource limits. - Setup: The child process:
- Sets the hostname.
- Bind-mounts the rootfs to itself (required for
pivot_root). - Uses
pivot_rootto swap the root filesystem and unmounts the old root. - Mounts
/proc. - Brings up the
loloopback interface.
- Exec: Replaces the child process with the target command using
execvp.
- Linux Kernel with Cgroups v2 support.
- Root privileges (or
CAP_SYS_ADMINcapabilities). g++andmake.
makeDownload and extract a minimalist Alpine RootFS:
./setup_rootfs.shsudo ./vortex run ./rootfs /bin/shInside the container, you can verify isolation:
# Check PID
ps aux
# Check Hostname
hostname
# Check Filesystem
ls /src/vortex.cpp: Main implementation.Makefile: Build instructions.setup_rootfs.sh: Script to prepare the container image.rootfs/: Directory containing the extracted Alpine Linux.