A minimal Linux container runtime written in C++. This project demonstrates how containerization works at the kernel level by using Linux namespaces, chroot, and mount operations to create an isolated environment — similar in concept to Docker, but built from scratch.
The program creates a new process in isolated Linux namespaces using the clone() system call with the following namespace flags:
| Namespace | Flag | Purpose |
|---|---|---|
| UTS | CLONE_NEWUTS |
Isolated hostname (minicontainer) |
| Mount | CLONE_NEWNS |
Independent filesystem mount points |
| PID | CLONE_NEWPID |
Separate process ID space |
| IPC | CLONE_NEWIPC |
Isolated inter-process communication |
| Cgroup | CLONE_NEWCGROUP |
Separate cgroup hierarchy |
| User | CLONE_NEWUSER |
Independent user/group IDs |
Inside the new namespace, the program:
- Sets up
/tmp/container_rootas the container's root filesystem usingchroot - Mounts a private
/procfilesystem for process visibility - Sets the hostname to
minicontainer - Launches an interactive Bash shell
- Linux with namespace support (kernel 3.8+)
- C++ compiler (GCC / G++)
- make
- A populated root filesystem at
/tmp/container_root(e.g. viadebootstrap)
make # compiles the 'container' binaryOther Makefile targets:
make clean # remove object files
make fclean # remove object files and the binary./containerThis drops you into an interactive Bash shell running inside the container with an isolated hostname, PID space, and mount namespace.
Note: Creating namespaces may require elevated privileges (root or
CAP_SYS_ADMIN). You may need to run the binary withsudo.
The container expects a root filesystem at /tmp/container_root. You can create one with debootstrap (Debian/Ubuntu):
sudo apt-get install debootstrap
sudo debootstrap stable /tmp/container_root http://deb.debian.org/debian/.
├── Makefile # Build configuration
├── minicontainer.cpp # Container runtime implementation
└── Readme.md # This file