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:
We now provide a script that handles dependencies, auto-detects the latest Alpine version, and configures port forwarding for the GUI.
wget https://raw.githubusercontent.com/trefeon/Docker-Termux/main/install.sh
chmod +x install.sh
./install.shIf you prefer to do it manually, follow these steps:
-
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 separate directory:
mkdir alpine && cd alpine- Download the latest Alpine Linux (virt optimized) ISO:
# Get latest version name
ISO_NAME=$(curl -s https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/ | grep -oE 'alpine-virt-[0-9.]+-x86_64.iso' | head -n 1)
# Download it
wget https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/$ISO_NAME- Create a 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 (Replace $ISO_NAME with the file you downloaded):
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 $ISO_NAME -nographic alpine.img-
Login with username
root(no password). -
Set up the 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]After that, bring up the interface:
ifup eth0- Create an answerfile to speed up the installation:
wget https://raw.githubusercontent.com/trefeon/Docker-Termux/main/answerfileNOTE: If you see any error like this:
wget: bad address 'gist.githubusercontent.com', run the following command:echo -e "nameserver 192.168.1.1\nnameserver 1.1.1.1" > /etc/resolv.conf
- Patch
setup-diskto enable serial console output on boot:
sed -i -E 's/(local kernel_opts)=.*/\1="console=ttyS0"/' /sbin/setup-disk- Run the setup to install Alpine to the disk:
setup-alpine -f answerfile-
Once the installation is complete, power off the VM using the
poweroffcommand. -
Boot again without the CD-ROM:
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.imgnano run_qemu.shIn the text editor, add 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.imgSave and exit.
chmod +x run_qemu.sh./run_qemu.sh- Update the 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 to start on boot:
rc-update add docker- Check if Docker was installed successfully:
docker run hello-worldCtrl+a x: Quit emulation.Ctrl+a h: Toggle QEMU console.
To manage your containers with a beautiful web interface, follow these steps inside the Alpine VM:
- Install and start Docker:
apk add docker
service docker start
rc-update add docker- Run Portainer CE:
docker run -d -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer-ce:latest- Access the GUI:
Open your Android browser and go to: http://localhost:9000
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 project is licensed under the MIT License.