docker-android

docker-android

虚拟化环境准备

VMware 中的虚拟机开启虚拟化

开启 VMware 中的虚拟机的虚拟化,其实就是开启VMware 中的虚拟机的 IntelVT-x/EPT或AMD-V/RVI(V)。

进入虚拟机的设置界面,选择"硬件",然后选择"处理器",然后勾选"虚拟化 IntelVT-x/EPT或AMD-V/RVI(V)",此时我们就开启了 VMware 中虚拟机的虚拟化

此时,如果没有经过本文档后续的系统配置 ,那么你大概率会出现类似 此平台不支持虚拟化的IntelVT-x/EPT 的报错

检查自己的电脑是否开启了虚拟化

<Ctrl-Shift-Esc>,点击"性能->CPU",查看"虚拟化"是否显示"已启用"。

如果没有开启,则需要进入主板的 BIOS 中开启虚拟化功能,由于不同的主板进入 BIOS 开启虚拟化的方式略有不同,所以这里不讲述如何操作

关闭 Windows 自带的虚拟机功能

<win-r,control>,点击<启用或关闭Windows功能>,取消勾选“Hyper-V”、“Windows虚拟机监控程序平台”、“虚拟机平台”,然后重启电脑。

禁用 Windows 自带的虚拟机的相关服务

<win-r,services.msc>,禁用 Windows 自带的虚拟机 Hyper-V 的相关服务:

  1. HV 主机服务
  2. Hyper-V 卷影复制请求程序
  3. Hyper-V 主机计算服务

停止 hypervisorlaunchtype(Windows Hyper-V 启动加载器)

以管理员的身份打开命令行窗口,运行如下命令,关闭停止 Windows Hyper-V 启动加载器

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 开启 Windows Hyper-V 启动加载器,以管理员的身份在运行命令行窗口运行:
bcdedit /set hypervisorlaunchtype auto
# 或
bcdedit /set hypervisorlaunchtype on

# 关闭 Windows Hyper-V 启动加载器
bcdedit /set hypervisorlaunchtype off

# 还是以管理员的身份,运行如下命令,检查 Windows Hyper-V 启动加载器是否关闭停止
bcdedit /enum
# hypervisorlaunchtype Off 即 Windows Hyper-V 启动加载器关闭停止

重启 VMware 虚拟机

接下来,在开启虚拟机的虚拟化 IntelVT-x/EPT或AMD-V/RVI(V) 的情况下,再次启动虚拟机即可正常启动

Quick Start

  1. If you use Ubuntu OS on your host machine, you can skip this step. For OSX and Windows OS user, you need to use Virtual Machine that support Virtualization with Ubuntu OS because the image can be run under Ubuntu OS only.
  2. Your machine should support virtualization. To check if the virtualization is enabled is:

    1
    2
    
    sudo apt install cpu-checker
    kvm-ok
  3. Run Docker-Android container

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    
    # 容器如果不存在则pull,并且运行,如果已存在该容器则跳过,并且没有运行的容器也不会运行
    sudo docker run -d -p 6080:6080 -e EMULATOR_DEVICE="Samsung Galaxy S10" -e WEB_VNC=true --device /dev/kvm --name android-container budtmo/docker-android:emulator_11.0
    # 或,映射ADB端口,开放5554/5555端口
    sudo docker run \
      -d \
      -p 6080:6080 \
      -p 5554:5554 -p 5555:5555 \
      -e EMULATOR_DEVICE="Samsung Galaxy S10" \
      -e WEB_VNC=true \
      --device /dev/kvm \
      --name android-container \
      budtmo/docker-android:emulator_11.0
    # 或
    sudo docker run \
      -d \
      -p 6080:6080 \
      -p 5554:5554 -p 5555:5555 \
      -e EMULATOR_DEVICE="Samsung Galaxy S10" \
      -e WEB_VNC=true \
      --device /dev/kvm \
      --name android-container \
      budtmo/docker-android:emulator_11.0
    
    # 运行容器
    sudo docker run \
      -d \
      -p 6080:6080 \
      -p 5554:5554 -p 5555:5555 \
      -e EMULATOR_DEVICE="Samsung Galaxy S10" \
      -e WEB_VNC=true \
      --device /dev/kvm \
      -it budtmo/docker-android:emulator_11.0
  4. Open http://localhost:6080 to see inside running container.
  5. To check the status of the emulator

    1
    2
    3
    4
    
    # device_status不会立马出现,需要等待一段时间才会被创建
    sudo docker exec -it android-container cat device_status
    # 或,进入容器
    sudo docker run -it budtmo/docker-android:emulator_11.0 bash

完整操作顺序(推荐直接复制执行)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 1. 停掉正在运行的旧模拟器容器
docker stop relaxed_shamir
# 2. 删除旧容器释放端口
docker rm relaxed_shamir
# 3. 删除刚才启动失败的 android-container
docker rm android-container
# 4. 重新拉起全新容器
sudo docker run \
     -d \
     -p 6080:6080 \
     -p 5554:5554 -p 5555:5555 \
     -e EMULATOR_DEVICE="Samsung Galaxy S10" \
     -e WEB_VNC=true \
     --device /dev/kvm \
     --name android-container \
     budtmo/docker-android:emulator_11.0
启动成功后,用下面命令看模拟器启动日志,确认安卓开机
1
docker logs -f android-container

scrcpy远程控制示例

1
2
3
4
# adb连接安卓设备
adb connect 192.168.x.x:5555
# scrcpy远程控制安卓设备
scrcpy -s 192.168.x.x

参考链接