Skip to content

Instantly share code, notes, and snippets.

@oofnikj
Last active April 14, 2024 05:15
Show Gist options
  • Save oofnikj/e79aef095cd08756f7f26ed244355d62 to your computer and use it in GitHub Desktop.
Save oofnikj/e79aef095cd08756f7f26ed244355d62 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.12/main http://dl-cdn.alpinelinux.org/alpine/v3.12/community"
SSHDOPTS="-c openssh"
NTPOPTS="-c busybox"
DISKOPTS="-v -m sys -s 0 /dev/sda"

Docker on Termux [in a VM]

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 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
    
  • 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
@Saikatsaha1996
Copy link

# service start docker

Above command works fine and docker daemon also runs, but if I run any docker commands I get Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Also did this -

# /usr/bin/dockerd

It throws error -

WARN[2022-11-11T18:53:34.552116680Z] grpc: addrConn.createTransport failed to connect to {unix:///var/run/docker/containerd/containerd.sock 0 }. Err :connection error: desc = "transport: error while dialing: dial unix:///var/run/docker/containerd/containerd.sock: timeout". Reconnecting... module=grpc

ANY HELP WOULD BE APPRECIATED!

Use this one
https://github.com/sylirre/vmConsole

@YashIndane
Copy link

YashIndane commented Nov 12, 2022

Use this one https://github.com/sylirre/vmConsole

@Saikatsaha1996 Thanks, this works, but In this the VM is not getting ip address like 192.168.x.x so that I can ssh. How to do that?

@Saikatsaha1996
Copy link

Use this one https://github.com/sylirre/vmConsole

@Saikatsaha1996 Thanks, this works, but In this the VM is not getting ip address like 192.168.x.x so that I can ssh. How to do that?

Please ask here https://github.com/sylirre/vmConsole/issues

@fran6120
Copy link

fran6120 commented Nov 17, 2022

It works fine on a OnePlus 5 with Termux 0.118.0 (118) F-Droid, but it takes a long time to start and the containers feel very slow.

Welcome to Termux!

Community forum: https://termux.com/community
Gitter chat:     https://gitter.im/termux/termux
IRC channel:     #termux on libera.chat

Working with packages:

 * Search packages:   pkg search <query>
 * Install a package: pkg install <package>
 * Upgrade packages:  pkg upgrade

Subscribing to additional repositories:

 * Root:     pkg install root-repo
 * X11:      pkg install x11-repo

Report issues at https://termux.com/issues

~ $ cd alpine
qemu-system-x86_64 -machine q35 -m 2048 -smp cpus=4 -cpu qemu64 \
  -drive if=pflash,format=raw,read-only=on,file=$PREFIX/share/qemu/edk2-x86_64-code.fd \
  -netdev user,id=n1,hostfwd=tcp::8123-:8123,hostfwd=tcp::9000-:9000,hostfwd=tcp::6052-:6052,hostfwd=tcp::49154-:49154,hostfwd=tcp::61208-:61208,hostfwd=tcp::3218-:3218 \
  -device virtio-net,netdev=n1 \
  -nographic alpine_2.qcow2
BdsDxe: failed to load Boot0001 "UEFI QEMU DVD-ROM QM00005 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x2,0xFFFF,0x0): Not Found
BdsDxe: loading Boot0002 "UEFI QEMU HARDDISK QM00001 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)
BdsDxe: starting Boot0002 "UEFI QEMU HARDDISK QM00001 " from PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)
Welcome to GRUB!


Welcome to Alpine Linux 3.16
Kernel 5.15.78-0-virt on an x86_64 (/dev/ttyS0)

alpineop5 login: root
Password:
Welcome to Alpine!

The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <http://wiki.alpinelinux.org/>.

You can setup the system with the command: setup-alpine

You may change this message by editing /etc/motd.

alpineop5:~# docker ps
CONTAINER ID   IMAGE                                          COMMAND                  CREATED          STATUS                             PORTS                                                           NAMES
b302dadea6a2   ghcr.io/home-assistant/home-assistant:latest   "/init"                  44 minutes ago   Up 2 minutes                                                                                       homeassistant
e59c38ef7d00   causticlab/hass-configurator-docker:latest     "/app/run.sh"            51 minutes ago   Up 13 seconds                      0.0.0.0:3218->3218/tcp, :::3218->3218/tcp                       configurador-hass-configurator-1
a37544f8da52   esphome/esphome                                "/entrypoint.sh dash…"   5 hours ago      Up 2 minutes                                                                                       esphome
b7ea2ae49547   filebrowser/filebrowser:latest                 "/filebrowser --noau…"   5 hours ago      Up 13 seconds (health: starting)   0.0.0.0:49154->80/tcp, :::49154->80/tcp                         archivos-filebrowser-1
645d8e7d288e   portainer/portainer-ce:latest                  "/portainer"             5 hours ago      Up 58 seconds                      8000/tcp, 9443/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp   portainer
alpineop5:~#

@Itsfadixx
Copy link

same

@szcharlesji
Copy link

It works for me on OnePlus 5. Is there a way to log into the alpine vm without restarting it each time? Thanks!

@fran6120
Copy link

It works for me on OnePlus 5. Is there a way to log into the alpine vm without restarting it each time? Thanks!

If you only want to run docker and not use android apps the best solution is move from android to postmarketos (Alpine Linux distro) and run docker natively.

@DeicPro
Copy link

DeicPro commented Mar 3, 2023

I tried default commands and modified with updated Alpine and don't get internet :(

localhost:~# ifup eth0
udhcpc: started, v1.31.1
udhcpc: sending discover
udhcpc: sending select for 10.0.2.15
udhcpc: lease of 10.0.2.15 obtained, lease time 86400
localhost:~# wget https://gist.githubusercontent.com/oofnikj/e79aef095cd08756f7f
26ed244355d62/raw/answerfile
wget: bad address 'gist.githubusercontent.com'

@DeicPro
Copy link

DeicPro commented Mar 4, 2023

I tried default commands and modified with updated Alpine and don't get internet :(

localhost:~# ifup eth0
udhcpc: started, v1.31.1
udhcpc: sending discover
udhcpc: sending select for 10.0.2.15
udhcpc: lease of 10.0.2.15 obtained, lease time 86400
localhost:~# wget https://gist.githubusercontent.com/oofnikj/e79aef095cd08756f7f
26ed244355d62/raw/answerfile
wget: bad address 'gist.githubusercontent.com'

Well the issue was the DNS settings, because doing ping to IPs instead domains is a check of that internet works. For some reason, eth0 router IP doesn't link correctly the real router IP, and then can't get the DNS of it... So the fix is as easy as set manually the IP of your router and/or optionally a DNS IP of your choice (for example Cloudflare DNS):

echo "nameserver 192.168.1.1
nameserver 1.1.1.1" > /etc/resolv.conf

It's important to configure eth0 as manual instead dhcp, because this file will be overwrote with default values everytime the network is restarted. More info here

@Nothig00
Copy link

Nothig00 commented Mar 14, 2023

alpine:~# apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/community: temporary error (try again later)
v3.12.12-45-g8116a127ec [http://dl-cdn.alpinelinux.org/alpine/v3.12/main]
v3.12.12-46-g1df69604c4 [http://dl-cdn.alpinelinux.org/alpine/v3.12/community]
2 errors; 12763 distinct packages available
alpine:~# curl -v -s http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKIN
DEX.tar.gz > /dev/null
-ash: curl: not found
alpine:~# apk add curl
(1/16) Installing ca-certificates (20220614-r0)
ERROR: ca-certificates-20220614-r0: temporary error (try again later)
(2/16) Installing nghttp2-libs (1.41.0-r0)
ERROR: nghttp2-libs-1.41.0-r0: temporary error (try again later)
(3/16) Installing libcurl (7.79.1-r1)
ERROR: libcurl-7.79.1-r1: temporary error (try again later)
(4/16) Installing curl (7.79.1-r1)
ERROR: curl-7.79.1-r1: temporary error (try again later)
(5/16) Installing libseccomp (2.4.4-r0)
ERROR: libseccomp-2.4.4-r0: temporary error (try again later)
(6/16) Installing runc (1.0.0_rc95-r0)
ERROR: runc-1.0.0_rc95-r0: temporary error (try again later)
(7/16) Installing containerd (1.4.4-r0)

Error which all ready have solved gliderlabs/docker-alpine#334 (comment) but I'm confused about command.

And one more littel help how can i setup this for selenium python.

@DeicPro
Copy link

DeicPro commented Mar 19, 2023

alpine:~# apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/community: temporary error (try again later)
v3.12.12-45-g8116a127ec [http://dl-cdn.alpinelinux.org/alpine/v3.12/main]
v3.12.12-46-g1df69604c4 [http://dl-cdn.alpinelinux.org/alpine/v3.12/community]
2 errors; 12763 distinct packages available
alpine:~# curl -v -s http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKIN
DEX.tar.gz > /dev/null
-ash: curl: not found
alpine:~# apk add curl
(1/16) Installing ca-certificates (20220614-r0)
ERROR: ca-certificates-20220614-r0: temporary error (try again later)
(2/16) Installing nghttp2-libs (1.41.0-r0)
ERROR: nghttp2-libs-1.41.0-r0: temporary error (try again later)
(3/16) Installing libcurl (7.79.1-r1)
ERROR: libcurl-7.79.1-r1: temporary error (try again later)
(4/16) Installing curl (7.79.1-r1)
ERROR: curl-7.79.1-r1: temporary error (try again later)
(5/16) Installing libseccomp (2.4.4-r0)
ERROR: libseccomp-2.4.4-r0: temporary error (try again later)
(6/16) Installing runc (1.0.0_rc95-r0)
ERROR: runc-1.0.0_rc95-r0: temporary error (try again later)
(7/16) Installing containerd (1.4.4-r0)

Error which all ready have solved gliderlabs/docker-alpine#334 (comment) but I'm confused about command.

And one more littel help how can i setup this for selenium python.

setup-interfaces
ifup -a
setup-interfaces
echo 1.1.1.1 > /etc/resolv.conf

Only press enter in all setup-interfaces questions.

@DeicPro
Copy link

DeicPro commented Mar 19, 2023

@oofnikj add DNSOPTS="1.1.1.1" to the answer file to fix DNS issue and change APKREPOSOPTS to:

APKREPOSOPTS="http://dl-cdn.alpinelinux.org/alpine/latest-stable/main http://dl-cdn.alpinelinux.org/alpine/latest-stable/community"

@alick97
Copy link

alick97 commented Mar 25, 2023

when setup-disk error and not installed to alpine.img, you can run qemu with -hda alpine.img and export ERASE_DISKS=/dev/sda before setup-alpine

@directentis1
Copy link

directentis1 commented Apr 1, 2023

Is it works on proot (fake root) on some interactive shells?

Everything is okay until the boot qemu step, i got this error: qemu-system-x86_64: -drive if=pflash,format=raw,read-only,file=/usr/share/qemu/edk2-x86_64-code.fd: Could not open '/usr/share/qemu/edk2-x86_64-code.fd': No such file or directory

btw, I can't install qemu-common qemu-system-x86_64-headless with proot on my debian machine.

@sdshan8
Copy link

sdshan8 commented Apr 1, 2023

Is it works on proot (fake root) on some interactive shells?

Everything is okay until the boot qemu step, i got this error: qemu-system-x86_64: -drive if=pflash,format=raw,read-only,file=/usr/share/qemu/edk2-x86_64-code.fd: Could not open '/usr/share/qemu/edk2-x86_64-code.fd': No such file or directory

btw, I can't install qemu-common qemu-system-x86_64-headless with proot on my debian machine.

Try Installing qemu-system-x86_64-headless in termux then using /data/data/com.termux/files/usr/share/qemu/edk2-x86_64-code.fd instead of /usr/share/qemu/edk2-x86_64-code.fd

@directentis1
Copy link

Is it works on proot (fake root) on some interactive shells?
Everything is okay until the boot qemu step, i got this error: qemu-system-x86_64: -drive if=pflash,format=raw,read-only,file=/usr/share/qemu/edk2-x86_64-code.fd: Could not open '/usr/share/qemu/edk2-x86_64-code.fd': No such file or directory
btw, I can't install qemu-common qemu-system-x86_64-headless with proot on my debian machine.

Try Installing qemu-system-x86_64-headless in termux then using /data/data/com.termux/files/usr/share/qemu/edk2-x86_64-code.fd instead of /usr/share/qemu/edk2-x86_64-code.fd

Umm, but I mean I'm using Interactive Shells from Amazon Cloud9, I don't have root privileges on it so wondering is it possible to install Docker via proot?

@Joanvoo
Copy link

Joanvoo commented Apr 4, 2023

i have no internet why?

localhost:# ifup eth0
udhcpc: started, v1.31.1
udhcpc: sending discover
udhcpc: sending select for 10.0.2.15
udhcpc: lease of 10.0.2.15 obtained, lease time 86400
localhost:
# wget https://gist.githubusercontent.com/oofnikj/e79aef095cd08756f7f
26ed244355d62/raw/answerfile
wget: bad address 'gist.githubusercontent.com'
edit:
This network setting work for me:
localhost: # echo -e "auto lo\niface lo inet loopback\nauto eth0\niface eth0 inet dhcp" > /etc/network/interfaces
localhost: # /etc/init.d/networking restart
localhost:~# echo nameserver 1.1.1.1 > /etc/resolv.conf
nameserver 8.8.8.8 does not work for me

@sdshan8
Copy link

sdshan8 commented Apr 5, 2023

Is it works on proot (fake root) on some interactive shells?
Everything is okay until the boot qemu step, i got this error: qemu-system-x86_64: -drive if=pflash,format=raw,read-only,file=/usr/share/qemu/edk2-x86_64-code.fd: Could not open '/usr/share/qemu/edk2-x86_64-code.fd': No such file or directory
btw, I can't install qemu-common qemu-system-x86_64-headless with proot on my debian machine.

Try Installing qemu-system-x86_64-headless in termux then using /data/data/com.termux/files/usr/share/qemu/edk2-x86_64-code.fd instead of /usr/share/qemu/edk2-x86_64-code.fd

Umm, but I mean I'm using Interactive Shells from Amazon Cloud9, I don't have root privileges on it so wondering is it possible to install Docker via proot?

i cant help with that, try copying the edk2 file to the interactive shell somehow

@RedstoneWizard08
Copy link

i have no internet why?

localhost:# ifup eth0 udhcpc: started, v1.31.1 udhcpc: sending discover udhcpc: sending select for 10.0.2.15 udhcpc: lease of 10.0.2.15 obtained, lease time 86400 localhost:# wget https://gist.githubusercontent.com/oofnikj/e79aef095cd08756f7f 26ed244355d62/raw/answerfile wget: bad address 'gist.githubusercontent.com'

Yea same here

localhost:~# ifup -a
udhcpc: started, v1.35.0
udhcpc: broadcasting discover
udhcpc: broadcasting select for 10.0.2.15, server 10.0.2.2
udhcpc: lease of 10.0.2.15 obtained from 10.0.2.2, lease time 86400
localhost:~# wget google.com
wget: bad address 'google.com'

@reski-rukmantiyo
Copy link

i have no internet why?
localhost:# ifup eth0 udhcpc: started, v1.31.1 udhcpc: sending discover udhcpc: sending select for 10.0.2.15 udhcpc: lease of 10.0.2.15 obtained, lease time 86400 localhost:# wget https://gist.githubusercontent.com/oofnikj/e79aef095cd08756f7f 26ed244355d62/raw/answerfile wget: bad address 'gist.githubusercontent.com'

Yea same here

localhost:~# ifup -a
udhcpc: started, v1.35.0
udhcpc: broadcasting discover
udhcpc: broadcasting select for 10.0.2.15, server 10.0.2.2
udhcpc: lease of 10.0.2.15 obtained from 10.0.2.2, lease time 86400
localhost:~# wget google.com
wget: bad address 'google.com'

change your dns into your own. scroll up

@rahuls360
Copy link

To debug/resolve the DNS issues follow the below steps. Hope it saves someone else few hours

ping 8.8.8.8 -> Worked for me
ping google.com -> Failed for me
Edit DNS file -> vm etc/resolv.conf -> Add google's DNS on 2nd line nameserver 8.8.8.8 (it doesn't work, try other DNS)
ping google.com will work now
ping gist.githubusercontent.com will also work
Continue with next steps

@chenoi
Copy link

chenoi commented May 15, 2023

Hi...after reboot all the setup answerfile, interface eth0 setup ....everything gone and I have to gone thru the whole process and once again after 'Once installation is complete, power off the VM (command poweroff) and boot again without cdrom:' everything gone....need some advise here to make it persistent. Thanks

@bassem-saeed
Copy link

After following these instructions I will be able to use docker and access device folder at the same time?
(device folders like /storage/emulated/0/

@qpqg
Copy link

qpqg commented Jul 21, 2023

i gave up, it seems there is no way to shared folder in qemu in termux

i even consulted it with ChatGPT
he taught me to write comments

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
-virtfs local,path=/data/data/com.termux/files/home,mount_tag=termux,security_model=none
~/alpine/alpine.img

but can't work.

@LeftandRights
Copy link

I tried running a Flask server in it and listen to port 5000 and host 0.0.0.0 which supposed to be accessible to all devices that connected to the same router. But in this case i can't even access it through my browser. Feel free to reply, any help will be appreciated.

@Petrik-a-dost
Copy link

Petrik-a-dost commented Aug 18, 2023

Hi all, I installed portainer to docker

image

and it looks good but I can't connect from outside eg: it dosn't work 192.168.1.XX:9000 for portainer:

image

Do you know anyebody where is the problem? Thanks so much

EDIT: I have nonroot mobile

@LeftandRights
Copy link

LeftandRights commented Aug 18, 2023

Perhaps the issue might be located within the QEMU starting command itself. You need to specify the hostfwd flag along with the port you intend to use. For example, use -hostfwd=tcp::9000-:9001. What this flag does is to forward TCP traffic from port 9000 on the host to port 9001 on the guest. In other words, any incoming traffic directed at port 9000 on the host will be redirected to port 9001 within the virtual machine.

@Petrik-a-dost
Copy link

Perhaps the issue might be located within the QEMU starting command itself. You need to specify the hostfwd flag along with the port you intend to use. For example, use -hostfwd=tcp::9000-:9001. What this flag does is to forward TCP traffic from port 9000 on the host to port 9001 on the guest. In other words, any incoming traffic directed at port 9000 on the host will be redirected to port 9001 within the virtual machine.

I don’t know if it is right because if I have more services with different ports?

@LeftandRights
Copy link

LeftandRights commented Aug 18, 2023

Perhaps the issue might be located within the QEMU starting command itself. You need to specify the hostfwd flag along with the port you intend to use. For example, use -hostfwd=tcp::9000-:9001. What this flag does is to forward TCP traffic from port 9000 on the host to port 9001 on the guest. In other words, any incoming traffic directed at port 9000 on the host will be redirected to port 9001 within the virtual machine.

I don’t know if it is right because if I have more services with different ports?

I don't know if there's a better way to do this, but if you want to forward multiple ports, you could've use the hostfwd flag multiple times. This is how the command would looks like -hostfwd=tcp::8080-:80,hostfwd=tcp::9000-:8081. This is how i usually forward ports on QEMU so, hope it helps.

@Petrik-a-dost
Copy link

-hostfwd=tcp::8080-:80 -hostfwd=tcp::9000-:8081

if I use this command:
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 -hostfwd=tcp::8080-:80 -hostfwd=tcp::9000-:8081 -device virtio-net,netdev=n1 -nographic alpine.img

I gets this message:
qemu-system-x86_64: -hostfwd=tcp::2222-:22: invalid option

@Petrik-a-dost
Copy link

@LeftandRights maybe I think it looks like that portforwarding between Termux and VM Alpine not working because If I try ping in termux to vm alpine (ping 10.0.2.15) I get icmp_seq=10 Time to live exceeded, but in VM Alpine is eth0: 10.0.2.15. What do you mean?

@LeftandRights
Copy link

@LeftandRights maybe I think it looks like that portforwarding between Termux and VM Alpine not working because If I try ping in termux to vm alpine (ping 10.0.2.15) I get icmp_seq=10 Time to live exceeded, but in VM Alpine is eth0: 10.0.2.15. What do you mean?

Although it shows 10.0.2.15 on the VM, it actually forwarded to your machine IPv4 address (192.168.1.32)

@Petrik-a-dost
Copy link

@LeftandRights maybe I think it looks like that portforwarding between Termux and VM Alpine not working because If I try ping in termux to vm alpine (ping 10.0.2.15) I get icmp_seq=10 Time to live exceeded, but in VM Alpine is eth0: 10.0.2.15. What do you mean?

Although it shows 10.0.2.15 on the VM, it actually forwarded to your machine IPv4 address (192.168.1.32)

OK, if I try ping from VM Alpine to Termux so in alpine:~# ping 192.168.1.32 I get: 64 bytes from 192.168.1.32: seq=2 ttl=255 time=6.812 ms. In this case it looks ok

@Petrik-a-dost
Copy link

@LeftandRights so this mean that I can from VM Alpine to Termux but I cann't from Termux to VM Alpine?

@LeftandRights
Copy link

LeftandRights commented Aug 20, 2023

-hostfwd=tcp::8080-:80 -hostfwd=tcp::9000-:8081

if I use this command: 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 -hostfwd=tcp::8080-:80 -hostfwd=tcp::9000-:8081 -device virtio-net,netdev=n1 -nographic alpine.img

I gets this message: qemu-system-x86_64: -hostfwd=tcp::2222-:22: invalid option

Sorry for the previous comment, the hostfwd flag should be used along with the netdev flag which turns out be something like this
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,hostfwd=tcp::8080-:80,hostfwd=tcp::9000-:8081 -device virtio-net,netdev=n1 -nographic alpine.img

@lexavey
Copy link

lexavey commented Oct 8, 2023

Out of box ! Thankyou !!!!!!!!!!

@valorisa
Copy link

When I launch Alpine with QEMU, I obtain this :

" Starting networking ... * lo ... [ ok ]

  • docker0 ...Cannot find device "docker0"
    Cannot find device "docker0"
    Device "docker0" does not exist.
    [ ok ]
  • eth0 ... [ ok ]
  • Seeding random number generator ... * Seeding 256 bits and crediting
  • Saving 256 bits of creditable seed for next boot
    [ ok ] "

@whyakari
Copy link

got internet error. so what I did:
vi /etc/resolv.conf

nameserver 8.8.8.8

:wq

@apchhi
Copy link

apchhi commented Dec 26, 2023

To avoid the connection problem that occurred with the authors of the posts above, you need to do the following:

  1. In the interface setup item localhost:~# setup-interfaces, select 2 items and 3 type "yes" instead of [no]
    Do you want to do any manual network configuration? [no] yes
  2. In the document that opens, paste this:
    auto lo
    iface lo inet loopback
    auto eth0
    iface eth0 inet static
    address 192.168.1.10
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 1.1.1.1
  3. Check:
    cat /etc/network/interfaces
  4. localhost:~# ifup eth0
  5. Check this file:
    cat /etc/resolve.conf
  6. If there is no such thing, then insert:
    echo "nameserver 192.168.1.1 nameserver 1.1.1.1" > /etc/resolv.conf
  7. localhost:~# /etc/init.d/networking restart
  8. if there are no errors, everything is ok

@shi-ivam
Copy link

shi-ivam commented Jan 7, 2024

echo "nameserver 192.168.1.1
nameserver 1.1.1.1" > /etc/resolv.conf

This works

@AntonyZ89
Copy link

Hello! 👋

I forked @egandro's qemu-docker-arm (great work!), did some refactoring to work with the latest version of Alpine (3.19) and added to the README @schnatterer's idea to connect and use docker in your terminal using ssh! Creating a great experience to use docker without needing root! 😄

repo: https://github.com/AntonyZ89/docker-qemu-arm

using docker compose to up my postgresql + redis:

Screen_Recording_20240118_144445_Termux-ezgif.com-crop-video.mp4

@mohit6350
Copy link

Thank you good sir !

@AlbertWang2018
Copy link

i have no internet why?

localhost:# ifup eth0 udhcpc: started, v1.31.1 udhcpc: sending discover udhcpc: sending select for 10.0.2.15 udhcpc: lease of 10.0.2.15 obtained, lease time 86400 localhost:# wget https://gist.githubusercontent.com/oofnikj/e79aef095cd08756f7f 26ed244355d62/raw/answerfile wget: bad address 'gist.githubusercontent.com' edit: This network setting work for me: localhost: # echo -e "auto lo\niface lo inet loopback\nauto eth0\niface eth0 inet dhcp" > /etc/network/interfaces localhost: # /etc/init.d/networking restart localhost:~# echo nameserver 1.1.1.1 > /etc/resolv.conf nameserver 8.8.8.8 does not work for me

Thanks for solving my problem. For me other problem is need modify /etc/apk/repositories enable community source, delete # in '#http://dl-cdn.alpinelinux.org/alpine/v3.12/community', otherwise run 'apk add docker' with error 'required by: world[docker-compose]'.

@zzduci
Copy link

zzduci commented Feb 23, 2024

I tried running a Flask server in it and listen to port 5000 and host 0.0.0.0 which supposed to be accessible to all devices that connected to the same router. But in this case i can't even access it through my browser. Feel free to reply, any help will be appreciated.

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,hostfwd=tcp::2222-:22,hostfwd=tcp::9000-:9000,hostfwd=tcp::4567-:4567,hostfwd=tcp::5344-:5344 -device virtio-net,netdev=n1
-cdrom alpine-virt-3.12.3-x86_64.iso -nographic alpine.img

like this ,portainer is working now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment