1.检测环境
root@xx:~# apt install cpu-checker
root@xx:~# kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
root@xx:~# ll /dev/kvm
crw-rw---- 1 root kvm 10, 232 Jan 15 16:38 /dev/kvm
确认/dev/kvm设备存在即可。如果是ESXi虚拟机服务器,则需要在虚拟机配置页面开启硬件虚拟化,也就是CPU虚拟化,如图:
如果是wsl2,则需要修改.wslconfig
配置文件中的nestedVirtualization=true
参数。
2.下载镜像
在https://hub.docker.com/r/halimqarroum/docker-android
页面中介绍了安卓模拟器的基本功能,但是该模拟器没有提供WEB访问页面,故在底部推荐一个自带WebRTC接口的镜像:https://github.com/budtmo/docker-android
,故下载镜像:
root@xx:~# docker pull budtmo/docker-android:emulator_14.0
//或者使用加速地址
root@xx:~# docker pull docker.1ms.run/budtmo/docker-android:emulator_14.0
root@xx:~# docker images | grep android
docker.1ms.run/budtmo/docker-android emulator_14.0 f17008029a69 4 days ago 8.38GB
docker.1ms.run/budtmo/docker-android emulator_11.0_v2.15.0-p0 bb2463579a08 4 days ago 7.34GB
注意,之前使用了emulator_11.0_v2.15.0-p0
版本,启动后无法访问,不知道具体原因,故使用最新的镜像,具体查看已发布页面或者Github介绍。
3.启动安卓模拟器镜像
root@xx:~# docker run -d -p 6080:6080 -e EMULATOR_DEVICE="Samsung Galaxy S10" -e WEB_VNC=true -e EMULATOR_ADDITIONAL_ARGS="-cores 6 -memory 5120" -e TZ=CST --device /dev/kvm --name android-container docker.1ms.run/budtmo/docker-android:emulator_14.0
root@xx:~# docker logs -f android-container
2025-01-15 08:36:38,053 INFO supervisord started with pid 8
2025-01-15 08:36:38,055 INFO supervisord started with pid 9
2025-01-15 08:36:38,060 INFO supervisord started with pid 7
2025-01-15 08:36:39,057 INFO spawned: 'android_port_forward' with pid 13
2025-01-15 08:36:39,059 INFO spawned: 'appium' with pid 14
2025-01-15 08:36:39,063 INFO spawned: 'device' with pid 15
2025-01-15 08:36:39,064 INFO spawned: 'd_screen' with pid 16
2025-01-15 08:36:39,067 INFO spawned: 'log_web_shared' with pid 17
2025-01-15 08:36:39,068 INFO spawned: 'd_wm' with pid 18
2025-01-15 08:36:39,072 INFO spawned: 'vnc_server' with pid 19
2025-01-15 08:36:39,076 INFO spawned: 'vnc_web' with pid 20
2025-01-15 08:36:39,803 INFO exited: appium (exit status 0; not expected)
2025-01-15 08:36:39,805 INFO gave up: appium entered FATAL state, too many start retries too quickly
2025-01-15 08:36:39,805 INFO exited: log_web_shared (exit status 0; not expected)
2025-01-15 08:36:40,142 INFO success: d_screen entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2025-01-15 08:36:40,142 INFO success: d_wm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2025-01-15 08:36:40,142 INFO success: vnc_server entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2025-01-15 08:36:40,142 INFO success: vnc_web entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2025-01-15 08:36:40,733 INFO success: android_port_forward entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2025-01-15 08:36:40,807 INFO success: device entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2025-01-15 08:36:40,810 INFO spawned: 'log_web_shared' with pid 62
2025-01-15 08:36:41,480 INFO exited: log_web_shared (exit status 0; not expected)
2025-01-15 08:36:43,491 INFO spawned: 'log_web_shared' with pid 69
2025-01-15 08:36:44,173 INFO exited: log_web_shared (exit status 0; not expected)
2025-01-15 08:36:47,181 INFO spawned: 'log_web_shared' with pid 71
2025-01-15 08:36:47,895 INFO exited: log_web_shared (exit status 0; not expected)
2025-01-15 08:36:48,897 INFO gave up: log_web_shared entered FATAL state, too many start retries too quickly
2025-01-15 08:41:43,388 INFO exited: device (exit status 1; not expected)
其中EMULATOR_ADDITIONAL_ARGS
设置模拟器的cpu和内存,--device /dev/kvm
参数很重要,影响启动速度和访问速度。
4.访问
访问6080
端口,页面如下:
点击链接,正常启动后如下:
启动后,大概3-5分钟就可以看见开机页面,通过谷歌浏览器下载和安装抖音,就是安装完成后运行比较卡顿,CPU使用率飙升,后台有个qemu的进程,应该是模拟器使用qemu启动的。