Skip to content

trefeon/Docker-Termux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Installing Docker in Termux

This repository contains instructions on how to install Docker in Termux, a powerful terminal emulator for Android.

Prerequisites

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.

Installation Steps

Follow the steps below to install Docker in Termux:

  1. Open Termux on your Android device.

  2. Update and upgrade the packages by running the following command:

pkg update -y && pkg upgrade -y
  1. Install the necessary dependencies by running the following command:
pkg install qemu-utils qemu-common qemu-system-x86_64-headless wget -y
  1. Create a separate directory:
mkdir alpine && cd alpine
  1. Download Alpine Linux 3.20.3 (virt optimized) ISO:
wget http://dl-cdn.alpinelinux.org/alpine/v3.20/releases/x86_64/alpine-virt-3.20.3-x86_64.iso
  1. Create a disk (note it won't actually take 5GB of space, more like 500-600MB):
qemu-img create -f qcow2 alpine.img 5G
  1. Boot it up:
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.3-x86_64.iso -nographic alpine.img
  1. Login with username root (no password).

  2. 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
  1. Create an answerfile to speed up the installation:
wget https://raw.githubusercontent.com/trefeon/Docker-Termux/main/answerfile

NOTE: 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
  1. Patch setup-disk to enable serial console output on boot:
sed -i -E 's/(local kernel_opts)=.*/\1="console=ttyS0"/' /sbin/setup-disk
  1. Run the setup to install Alpine to the disk:
setup-alpine -f answerfile
  1. Once the installation is complete, power off the VM using the poweroff command.

  2. 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.img

A. Create a script to simplify booting:

nano run_qemu.sh

In 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.img

Save and exit.

B. Make the script executable:

chmod +x run_qemu.sh

C. Run the script:

./run_qemu.sh
  1. 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
  1. Start Docker:
service docker start
  1. Enable Docker to start on boot:
rc-update add docker
  1. Check if Docker was installed successfully:
docker run hello-world

Some useful keys:

  • Ctrl+a x: Quit emulation.
  • Ctrl+a h: Toggle QEMU console.

Usage

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.

Contributing

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.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published