A simple and minimal replica of Docker - made for the purpose of learning.
It is not a fully-fledged container runtime.
Make sure you have the following installed in your system:
libcurl - for handling HTTP requests
sudo apt install libcurl4-openssl-dev
nlohmann:json - for JSON parsing
sudo apt install nlohmann-json3-dev
tar - for working with tar archives
sudo apt install tar
Build tools – includes make and gcc
sudo apt-get install build-essential.
In the root directory run :
make clean - to empty out the build directory first
make - to compile and get an executable
This will store a mini-docker executable under the ./build directory
After the build is complete, you can execute
sudo ./build/mini-docker run hello-world
The sudo is required because the program performs privileged operations such as:
- Creating cgroups
- Setting CPU and memory limits
- Mapping user and group IDs (UID/GID)
Other example images that you can run for testing:
sudo ./build/mini-docker run ubuntu:latest
sudo ./build/mini-docker run busybox:latest
sudo ./build/mini-docker run python:latest
Note: Since this tool implements only a minimal subset of Docker's functionality, some images may not run successfully.
The available commands are listed below:
| Functionality | Command | Description |
|---|---|---|
| Run Command | sudo ./build/mini-docker run-command <command> |
Execute a single CLI command like 'ls','echo',etc in a minimal root filesystem (e.g., alpine-minirootfs) Environment variable "MINIDOCKER_DEFAULT_FS" should be set to a valid path of a minimal root filesystem |
| Pull Image | sudo ./build/mini-docker pull <image name>[:<image_tag>] |
Pulls the image manifest, configuration and extracts the fs layers of the image into "/var/lib/minidocker/layers" It uses "/tmp/minidocker" to store tarballs downloaded temporarily |
| Run Container | sudo ./build/mini-docker run <image name>[:<image_tag>] |
Pulls image if not available locally and then runs it in a container Container fs is stored in "/var/lib/minidocker/containers" and destroyed at the end of the lifecycle |
Since this is just a minimal replica of Docker, there is plenty of room for improvement and additional features.
Some of the notable ones include:
- Currently, the container FS is created by copying the image layers into a container directory (minidocker-<hostname>). Ideally, we should use a Copy-On-Write Filesystem like OverlayFS. This will help us containerize images which rely on symlinks. It will also help us save space.
- Allow containers to run in the background (detached mode), similar to Docker's -d option.
- Allow customization of memory and cpu allocated for containers (using environment variables or config file)
- Add support for features like port mapping (e.g., -p 8080:80), which are essential for exposing containerized services.
- More metadata can be stored about the images and containers, which can be further used to list images, remove images, list containers along with their statuses, start, stop, and remove containers, etc.
Contributions are always welcome. You could open up an issue if you feel like something is wrong with the tool or a PR if you just want to improve it.