This repository contains instructions on how to install Docker in Termux, a powerful terminal emulator for Android.
Before proceeding with the installation, make sure you have the following prerequisites:
- An Android device with Termux installed. You can download Termux from the F-Droid app store.
- Stable internet connection.
Follow the steps below to install Docker in Termux:
-
Open Termux on your Android device.
-
Update and upgrade the packages by running the following command:
pkg update -y && pkg upgrade -y
- Install the necessary dependencies by running the following command:
pkg install qemu-utils qemu-common qemu-system-x86_64-headless wget -y
- Create a seperate directory:
mkdir alpine && cd alpine
- Download Alpine Linux 3.20.2 (virt optimized) ISO:
wget http://dl-cdn.alpinelinux.org/alpine/v3.20/releases/x86_64/alpine-virt-3.20.2-x86_64.iso
- Create disk (note it won't actually take 5GB of space, more like 500-600MB):
qemu-img create -f qcow2 alpine.img 5G
- Boot it up: Here we're using 1024MB of memory and 2 cpus
qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 -drive if=pflash,format=raw,read-only=on,file=$PREFIX/share/qemu/edk2-x86_64-code.fd -netdev user,id=n1,dns=8.8.8.8,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 -cdrom alpine-virt-3.20.2-x86_64.iso -nographic alpine.img
you can get number of useable cpus using
nproc
and total memory usingfree -m | grep -oP '\d+' | head -n 1
-
Login with username
root
(no password) -
Setup network (press Enter to use defaults):
localhost:~# setup-interfaces
Available interfaces are: eth0.
Enter '?' for help on bridges, bonding and vlans.
Which one do you want to initialize? (or '?' or 'done') [eth0]
Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp]
Do you want to do any manual network configuration? [no]
localhost:~#
ifup eth0
- Create an answerfile to speed up installation:
wget https://raw.githubusercontent.com/cyberkernelofficial/docker-in-termux/main/answerfile
NOTE: If you see any error like this:
wget: bad address 'gist.githubusercontent.com'
. Then run this commandecho -e "nameserver 192.168.1.1\nnameserver 1.1.1.1" > /etc/resolv.conf
- Patch
setup-disk
to enable serial console output on boot:
sed -i -E 's/(local kernel_opts)=.*/\1="console=ttyS0"/' /sbin/setup-disk
- Run setup to install to disk
setup-alpine -f answerfile
-
Once installation is complete, power off the VM (command
poweroff
) -
Boot again without cdrom:
qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 -drive if=pflash,format=raw,read-only=on,file=$PREFIX/share/qemu/edk2-x86_64-code.fd -netdev user,id=n1,dns=8.8.8.8,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 -nographic alpine.img
A -
nano run_qemu.sh
In the text editor, write the following:
#!/bin/bash
qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 -drive if=pflash,format=raw,read-only=on,file=$PREFIX/share/qemu/edk2-x86_64-code.fd -netdev user,id=n1,dns=8.8.8.8,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 -nographic alpine.img
Save and close the file. In nano, you can do this by pressing Ctrl+X, then Y to confirm saving, and then Enter to confirm the filename.
B - chmod command: chmod +x run_qemu.sh
C - ./run_qemu.sh
- Update system and install docker:
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
apk update && apk add docker
- Start docker:
service docker start
- Enable docker on boot:
rc-update add docker
- Check docker install successfully or not:
docker run hello-world
Ctrl+a x
: quit emulationCtrl+a h
: toggle QEMU console
Now that Docker is installed in Termux, you can start using it to manage and run containers on your Android device. Refer to the official Docker documentation for more information on how to use Docker.
If you encounter any issues during the installation process or have suggestions for improvements, please feel free to open an issue or submit a pull request.
- This article inspired from: https://gist.github.com/oofnikj/e79aef095cd08756f7f26ed244355d62
This project is licensed under the MIT License.