Run Docker in Termux (without root or QEMU) inside an isolated Debian VM powered by unkernel.
docker-vm.mjs manages a background VM, persists Docker images and packages on a sparse ext4 disk image in ~/.unkernel-docker, mounts your $HOME directory at the same path inside the VM, exposes the Docker daemon over both a Unix socket and TCP, and automatically forwards container/guest ports to 127.0.0.1 on the host.
This is similar to https://github.com/luisdavim/termux-qemu-docker but using unkernel instead of QEMU.
The idea is to provide a similar UX to lima and colima but with support for Android Termux.
- No QEMU required: Boots a Debian VM via WebAssembly (
unkernel). - Persistent storage: Stores
/var/lib/dockerand installed runtime packages on a sparse ext4 disk image (~/.unkernel-docker/docker-data.img, 16 GB by default). - Consistent path mapping: Mounts
$HOMEat the exact same path inside the VM so bind mounts anddockercommands work seamlessly from your working directory. - Automatic port forwarding: Discovers container
PortBindingsand guest listening TCP ports (>= 1024) and forwards them to127.0.0.1on Termux. - Transparent
-psupport: Proxies both the Unix socket and TCP API, rewritingdefault/bridgeNetworkModetohoston container creation so-p HOST:CONTAINERworks even from the native TermuxdockerCLI. - Interactive shell & wrapper: Run
execfor a shell in the VM ordockerto run commands without needing a localdockerclient.
- Node.js
>= 24(required byunkernel) e2fsprogs(formkfs.ext4ande2fsck)
On Termux:
pkg install -y nodejs e2fsprogsInstall npm dependencies in this repository:
npm installStart the VM in the background:
node ./docker-vm.mjs startNote: The first boot is expected to be slower (a few minutes) because it downloads the Debian image (cached in
~/.cache/unkernel), formats and checks the sparse disk image, and installs Docker andsocatinside the VM. Subsequent boots start Docker from the persisted package state.
Once healthy, connect your native docker CLI using either the Unix socket or TCP:
export DOCKER_HOST=unix://${HOME}/.unkernel-docker/docker.sockor:
export DOCKER_HOST=tcp://localhost:2375Then run Docker as usual:
docker run --rm hello-world
docker run --name some-nginx -it --rm -p 8080:80 nginxExposed ports (>= 1024) are automatically forwarded to 127.0.0.1:<port> on the host (e.g. http://127.0.0.1:8080).
| Command | Description |
|---|---|
node ./docker-vm.mjs start [options] |
Start the VM daemon in the background and wait until healthy |
node ./docker-vm.mjs status |
Show VM status, stage, PID, and forwarded ports as JSON |
node ./docker-vm.mjs exec |
Open an interactive root shell inside the VM |
node ./docker-vm.mjs exec <cmd...> |
Run a command inside the VM |
node ./docker-vm.mjs docker <args...> |
Run docker inside the VM (passes TTY, stdin, and $HOME-relative cwd) |
node ./docker-vm.mjs stop |
Gracefully stop Docker, unmount the data disk, and shut down the VM |
node ./docker-vm.mjs delete [-f] |
Stop the VM if running and delete all state in ~/.unkernel-docker |
start accepts --cpus <count> to set guest CPUs (default: 4),
--memory <MiB> to set guest memory (default: 4096 MiB), and
--disk <GB> to set the persistent disk size (default: 16 GB). For example:
node ./docker-vm.mjs start --cpus 2 --memory 4096 --disk 32The disk can be grown but not shrunk. Stop an already running VM before restarting it with different resource limits or disk size.
Open a shell in the VM:
node ./docker-vm.mjs execRun a command in the VM:
node ./docker-vm.mjs exec uname -aRun docker via the built-in wrapper (useful if you don't have the docker CLI installed on Termux):
node ./docker-vm.mjs docker run --name some-nginx -it --rm -p 8080:80 nginxRemove the VM and all persisted Docker data (skip prompt with -f / --force):
node ./docker-vm.mjs deleteAll VM state lives in ~/.unkernel-docker/:
docker-data.img— sparse ext4 persistent disk (16 GB by default)docker.sock— Host-side Docker Unix socket (owner-only permissions)ctl.sock— Control socket for CLI commandsvm.pid— Background daemon PIDvm.log— Daemon and boot logs (check here if startup fails)
The ext4 disk holds Docker data, /usr, /etc, and apt/dpkg state. Docker's runtime socket is recreated on each boot, and the filesystem is checked before mounting.