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.12 (virt optimized) ISO
mkdir alpine && cd $_ wget http://dl-cdn.alpinelinux.org/alpine/v3.12/releases/x86_64/alpine-virt-3.12.3-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=$PREFIX/share/qemu/edk2-x86_64-code.fd \ -netdev user,id=n1,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 \ -cdrom alpine-virt-3.12.3-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/oofnikj/e79aef095cd08756f7f26ed244355d62/raw/answerfile
-
Patch
setup-disk
to enable serial console output on bootlocalhost:~# sed -i -E 's/(local kernel_opts)=.*/\1="console=ttyS0"/' /sbin/setup-disk
-
Run setup to install to disk
localhost:~# setup-alpine -f answerfile
-
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=$PREFIX/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 alpine:~# service docker start alpine:~# rc-update add docker
-
Useful keys:
- Ctrl+a x: quit emulation
- Ctrl+a h: toggle QEMU console
Silly question. Do you have a USB ethernet pluged into your phone? Where did you get the eth0 device on your phone?
Try using ifconfig on your cellphone in termux:
This qemu param
-netdev user,id=n1,hostfwd=tcp::2222-:22
is an internal NAT. If you need more complex szenarios or want to shape the traffic for a specific IP, you have to jump into the documentation. I am no expert on this, but you can do really a lot.Please keep in mind. The qemu
-netdev
isn't a full feature blown VMware/VBox nat, bridge, host only network. Why? Stuff that is required from the Android OS (the Linux level below this) hasn't all modules enabled that are required for this - or - you can't even access the required userspace tools on a non rooted phone or without a Custom Rom. If you need that (which I don't - because I see no point in playing with that!) then you have to jump into phone rooting. Good luck with that!Yes. This is docker to run x86_64 images on ARM based cell phones. This is done on purpose. We want to run our PC based x86_64 images with this aporach here.
Feel free to adopt it to aarch64 or whatever if you want to run these type of images. This might a good starting point here. The
-drive if=pflash,format=raw,read-only,file=$PREFIX/share/qemu/edk2-x86_64-code.fd
will be different. You can do that and it's just reading the qemu manual and check how to boot aarm64/Alpine on that. It might be simpler to figure out the parameters for qemu to emulate a supported aarm64 board and to get an Alpine disk image. I see no point playing with that for me, because I need no aarch64 Docker on my cell phone.