年轻人第一台服务器:手机Termux免root运行Docker

发表:2年前 更新:1年前
Termux |
5430
| 4

安装 QEMU

 pkg install qemu-utils qemu-common qemu-system-x86_64-headless

下载 Alpine Linux 3.12(virt 优化)ISO

 mkdir alpine && cd $_
 wget http://dl-cdn.alpinelinux.org/alpine/v3.12/releases/x86_64/alpine-virt-3.12.3-x86_64.iso

创建磁盘(注意它实际上不会占用 4GB 的空间,更像是 500MB)

 qemu-img create -f qcow2 alpine.img 4G

启动

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

使用用户登录 root(无密码)

设置网络(按 Enter 使用默认值):

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]
ifup eth0

使用 oofnikj 准备好的 answerfile 安装系统

wget https://gist.githubusercontent.com/oofnikj/e79aef095cd08756f7f26ed244355d62/raw/answerfile

让开机时能输出信息

sed -i -E 's/(local kernel_opts)=.*/\1="console=ttyS0"/' /sbin/setup-disk

安装系统至硬盘,期间会要求建立 root 帐号的密码。

setup-alpine -f answerfile

先用 poweroff 指令关机,以后就用这条指令启动虚拟机(可自行写成 shell):

qemu-system-x86_64 -machine q35 -m 2048 -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::8081-:80 -device virtio-net,netdev=n1 \ 
  -nographic alpine.img 
#m是分配2GB内存,cpu是2核CPU,hostfwd则是把外部8081通讯端口转发到虚拟机的80通讯端口。

安装 docker,并设定开机自动启动服务。

apk update && apk add docker 
service docker start 
rc-update add docker

测试 Docker

进入 alpine 虚拟机后

执行以下命令

docker

#termux #docker #android

signature
保持理智

全部评论

zhuchunshu
最佳回复
发表 :2年前 | 修改过

参考链接

click me

next
Key

发表 :2年前 | 修改过

?️

next
fule

发表 :2年前

巧啦,前几天刚换下来一台手机,准备折腾玩一玩~

next
zhuchunshu

发表 :2年前
fule 发表 2年前
巧啦,前几天刚换下来一台手机,准备折腾玩一玩~

生命在于折腾和探索?️

评论

无权限

请登录后评论

RunPod公众号

赞助商

联系我们

QQ群:798695907

邮箱:laravel@88.com