Skip to content

Instantly share code, notes, and snippets.

@AntonyZ89
Forked from oofnikj/answerfile
Last active January 18, 2024 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AntonyZ89/cd64610ef49f9fbb6c8f8acff709483e to your computer and use it in GitHub Desktop.
Save AntonyZ89/cd64610ef49f9fbb6c8f8acff709483e to your computer and use it in GitHub Desktop.
Install Docker on Termux
KEYMAPOPTS="us us"
HOSTNAMEOPTS="-n alpine"
INTERFACESOPTS="auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
hostname alpine
"
TIMEZONEOPTS="-z UTC"
PROXYOPTS="none"
APKREPOSOPTS="http://dl-cdn.alpinelinux.org/alpine/v3.19/main http://dl-cdn.alpinelinux.org/alpine/v3.19/community"
SSHDOPTS="-c openssh"
NTPOPTS="-c busybox"
DISKOPTS="-v -m sys -s 0 /dev/sda"

Docker on Termux [in a VM] using proot-distro with Arch Linux

Warn: for Termux only, check the original gist, some paths are different.

Automatic script + using docker on CLI from outside of Alpine VM https://github.com/AntonyZ89/docker-qemu-arm

Create a Linux VM and install Docker in it so you can (slowly) run x86 Docker containers on your Android device.

Recommended to use SSH or external keyboard to execute the following commands unless you want sore thumbs. See https://wiki.termux.com/wiki/Remote_Access#SSH

  • Install QEMU

     pkg install qemu-utils qemu-common qemu-system-x86_64-headless
    
  • Download Alpine Linux 3.19 (virt optimized) ISO

     mkdir alpine && cd $_
     wget http://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-virt-3.19.0-x86_64.iso
    
  • Create disk (note it won't actually take 4GB of space, more like 500MB)

     qemu-img create -f qcow2 alpine.img 4G
    
  • Boot it up

    qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \
      -drive if=pflash,format=raw,read-only,file=/data/data/com.termux/files/usr/share/qemu/edk2-x86_64-code.fd \
      -netdev user,id=n1,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 \
      -cdrom alpine-virt-3.19.0-x86_64.iso \
      -nographic alpine.img
    
  • Login with user 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:

    localhost:~# wget https://gist.githubusercontent.com/AntonyZ89/cd64610ef49f9fbb6c8f8acff709483e/raw/answerfile
    
  • Patch setup-disk to enable serial console output on boot

    localhost:~# sed -i -E 's/(local kernel_opts)=.*/\1="console=ttyS0"/' /sbin/setup-disk
    
  • Run setup to install to disk

    localhost:~# setup-alpine -f answerfile
    
    • choose a password to root [opcional]
    • create a user
    • choose a password to your user [opcional]
    • erase the disk pressing Y
  • Once installation is complete, power off the VM (command poweroff) and boot again without cdrom:

    qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \
      -drive if=pflash,format=raw,read-only,file=/data/data/com.termux/files//share/qemu/edk2-x86_64-code.fd \
      -netdev user,id=n1,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 \
      -nographic alpine.img
    
  • Install docker and enable on boot:

    alpine:~# apk update && apk add docker docker-cli-compose
    alpine:~# service docker start
    alpine:~# rc-update add docker
    
  • Useful keys:

    • Ctrl+a x: quit emulation
    • Ctrl+a h: toggle QEMU console

Errors:

qemu-system-x86_64: alpine.img: Failed to get "write" lock
Is another process using the image [alpine.img]?

solution: kill qemu process

$ lsof | grep alpine.img

qemu-syst 30129 30130 qemu-syst u0_a322  12u      REG 254,58 3928817664   159434 /home/antonydev/alpine/alpine.img
qemu-syst 30129 30131 qemu-syst u0_a322  12u      REG 254,58 3928817664   159434 /home/antonydev/alpine/alpine.img
qemu-syst 30129 30133 qemu-syst u0_a322  12u      REG 254,58 3928817664   159434 /home/antonydev/alpine/alpine.img

$ kill -9 30129
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment