feat: add android-docker

This commit is contained in:
Sun-ZhenXing
2026-01-18 23:48:30 +08:00
parent 10313b35e9
commit 55318da0b2
12 changed files with 512 additions and 262 deletions

View File

@@ -0,0 +1,31 @@
# Docker Android image tag (e.g., api-33, api-33-playstore)
# DOCKER_ANDROID_VERSION=api-33
# Docker Android GPU image tag (used by the gpu profile)
# DOCKER_ANDROID_GPU_VERSION=api-33-cuda
# Host port overrides
# DOCKER_ANDROID_ADB_PORT_OVERRIDE=5555
# DOCKER_ANDROID_CONSOLE_PORT_OVERRIDE=5554
# KVM device path (Linux hosts only)
# DOCKER_ANDROID_KVM_DEVICE=/dev/kvm
# Optional ADB key directory for Play Store images
# DOCKER_ANDROID_KEYS_DIR=./keys
# Emulator settings
# DOCKER_ANDROID_DISABLE_ANIMATION=false
# DOCKER_ANDROID_DISABLE_HIDDEN_POLICY=false
# DOCKER_ANDROID_SKIP_AUTH=true
# DOCKER_ANDROID_MEMORY=8192
# DOCKER_ANDROID_CORES=4
# GPU settings
# DOCKER_ANDROID_GPU_COUNT=1
# Resource limits
# DOCKER_ANDROID_CPU_LIMIT=2
# DOCKER_ANDROID_MEMORY_LIMIT=8G
# DOCKER_ANDROID_CPU_RESERVATION=1
# DOCKER_ANDROID_MEMORY_RESERVATION=4G

View File

@@ -0,0 +1,59 @@
# Docker Android Emulator
[English](./README.md) | [中文](./README.zh.md)
This service deploys the HQarroum Docker Android emulator image.
## Usage
- Start the default emulator:
```bash
docker compose up -d
```
- Start with GPU acceleration:
```bash
docker compose --profile gpu up -d
```
- Connect with ADB:
```bash
adb connect 127.0.0.1:5555
```
## Services
- `docker_android`: Android emulator (default).
- `docker_android_gpu`: Android emulator with CUDA support (profile: `gpu`).
## Configuration
- `DOCKER_ANDROID_VERSION`: Image tag, default is `api-33`.
- `DOCKER_ANDROID_GPU_VERSION`: GPU image tag, default is `api-33-cuda`.
- `DOCKER_ANDROID_ADB_PORT_OVERRIDE`: Host port for ADB, default is `5555`.
- `DOCKER_ANDROID_CONSOLE_PORT_OVERRIDE`: Host port for emulator console, default is `5554`.
- `DOCKER_ANDROID_KVM_DEVICE`: KVM device path, default is `/dev/kvm`.
- `DOCKER_ANDROID_KEYS_DIR`: ADB key directory for Play Store images, default is `./keys`.
- `DOCKER_ANDROID_DISABLE_ANIMATION`: Disable animations, default is `false`.
- `DOCKER_ANDROID_DISABLE_HIDDEN_POLICY`: Disable hidden API policy, default is `false`.
- `DOCKER_ANDROID_SKIP_AUTH`: Skip ADB authentication, default is `true`.
- `DOCKER_ANDROID_MEMORY`: Emulator RAM in MB, default is `8192`.
- `DOCKER_ANDROID_CORES`: Emulator CPU cores, default is `4`.
- `DOCKER_ANDROID_GPU_COUNT`: Number of GPUs, default is `1`.
- `DOCKER_ANDROID_CPU_LIMIT`: CPU limit, default is `2`.
- `DOCKER_ANDROID_MEMORY_LIMIT`: Memory limit, default is `8G`.
- `DOCKER_ANDROID_CPU_RESERVATION`: CPU reservation, default is `1`.
- `DOCKER_ANDROID_MEMORY_RESERVATION`: Memory reservation, default is `4G`.
## Volumes
- `docker_android_data`: Android AVD data stored at `/data`.
## Notes
- Linux with KVM is required for performance. Ensure `/dev/kvm` is available.
- For Play Store images, set `DOCKER_ANDROID_VERSION=api-33-playstore` and place `adbkey` and `adbkey.pub` in the `./keys` directory.
- The emulator is headless and can be controlled with `scrcpy` after connecting ADB.

View File

@@ -0,0 +1,59 @@
# Docker Android Emulator
[English](./README.md) | [中文](./README.zh.md)
该服务用于部署 HQarroum 的 Docker Android Emulator 镜像。
## 使用方法
- 启动默认模拟器:
```bash
docker compose up -d
```
- 启动 GPU 加速:
```bash
docker compose --profile gpu up -d
```
- 使用 ADB 连接:
```bash
adb connect 127.0.0.1:5555
```
## 服务
- `docker_android`:默认 Android 模拟器。
- `docker_android_gpu`:带 CUDA 的 Android 模拟器Profile`gpu`)。
## 配置
- `DOCKER_ANDROID_VERSION`:镜像标签,默认 `api-33`。
- `DOCKER_ANDROID_GPU_VERSION`GPU 镜像标签,默认 `api-33-cuda`。
- `DOCKER_ANDROID_ADB_PORT_OVERRIDE`ADB 主机端口,默认 `5555`。
- `DOCKER_ANDROID_CONSOLE_PORT_OVERRIDE`:模拟器控制台端口,默认 `5554`。
- `DOCKER_ANDROID_KVM_DEVICE`KVM 设备路径,默认 `/dev/kvm`。
- `DOCKER_ANDROID_KEYS_DIR`Play Store 镜像的 ADB 密钥目录,默认 `./keys`。
- `DOCKER_ANDROID_DISABLE_ANIMATION`:禁用动画,默认 `false`。
- `DOCKER_ANDROID_DISABLE_HIDDEN_POLICY`:禁用隐藏 API 策略,默认 `false`。
- `DOCKER_ANDROID_SKIP_AUTH`:跳过 ADB 认证,默认 `true`。
- `DOCKER_ANDROID_MEMORY`模拟器内存MB默认 `8192`。
- `DOCKER_ANDROID_CORES`:模拟器 CPU 核心数,默认 `4`。
- `DOCKER_ANDROID_GPU_COUNT`GPU 数量,默认 `1`。
- `DOCKER_ANDROID_CPU_LIMIT`CPU 限制,默认 `2`。
- `DOCKER_ANDROID_MEMORY_LIMIT`:内存限制,默认 `8G`。
- `DOCKER_ANDROID_CPU_RESERVATION`CPU 预留,默认 `1`。
- `DOCKER_ANDROID_MEMORY_RESERVATION`:内存预留,默认 `4G`。
## 数据卷
- `docker_android_data`Android AVD 数据目录,挂载到 `/data`。
## 说明
- 建议在支持 KVM 的 Linux 主机上运行,确保 `/dev/kvm` 可用。
- Play Store 镜像请设置 `DOCKER_ANDROID_VERSION=api-33-playstore`,并将 `adbkey` 与 `adbkey.pub` 放到 `./keys` 目录。
- 模拟器为无界面模式ADB 连接后可使用 `scrcpy` 进行控制。

View File

@@ -0,0 +1,83 @@
x-defaults: &defaults
restart: unless-stopped
logging:
driver: json-file
options:
max-size: 100m
max-file: "3"
services:
docker_android:
<<: *defaults
image: ${GLOBAL_REGISTRY:-}halimqarroum/docker-android:${DOCKER_ANDROID_VERSION:-api-33}
ports:
- "${DOCKER_ANDROID_ADB_PORT_OVERRIDE:-5555}:5555"
- "${DOCKER_ANDROID_CONSOLE_PORT_OVERRIDE:-5554}:5554"
volumes:
- docker_android_data:/data
- ${DOCKER_ANDROID_KEYS_DIR:-./keys}:/keys:ro
environment:
- TZ=${TZ:-UTC}
- DISABLE_ANIMATION=${DOCKER_ANDROID_DISABLE_ANIMATION:-false}
- DISABLE_HIDDEN_POLICY=${DOCKER_ANDROID_DISABLE_HIDDEN_POLICY:-false}
- SKIP_AUTH=${DOCKER_ANDROID_SKIP_AUTH:-true}
- MEMORY=${DOCKER_ANDROID_MEMORY:-8192}
- CORES=${DOCKER_ANDROID_CORES:-4}
devices:
- "${DOCKER_ANDROID_KVM_DEVICE:-/dev/kvm}:/dev/kvm"
healthcheck:
test: ["CMD-SHELL", "adb devices 2>/dev/null | grep -q emulator"]
interval: 30s
timeout: 10s
retries: 5
start_period: 60s
deploy:
resources:
limits:
cpus: ${DOCKER_ANDROID_CPU_LIMIT:-2}
memory: ${DOCKER_ANDROID_MEMORY_LIMIT:-8G}
reservations:
cpus: ${DOCKER_ANDROID_CPU_RESERVATION:-1}
memory: ${DOCKER_ANDROID_MEMORY_RESERVATION:-4G}
docker_android_gpu:
<<: *defaults
profiles:
- gpu
image: ${GLOBAL_REGISTRY:-}halimqarroum/docker-android:${DOCKER_ANDROID_GPU_VERSION:-api-33-cuda}
ports:
- "${DOCKER_ANDROID_ADB_PORT_OVERRIDE:-5555}:5555"
- "${DOCKER_ANDROID_CONSOLE_PORT_OVERRIDE:-5554}:5554"
volumes:
- docker_android_data:/data
- ${DOCKER_ANDROID_KEYS_DIR:-./keys}:/keys:ro
environment:
- TZ=${TZ:-UTC}
- DISABLE_ANIMATION=${DOCKER_ANDROID_DISABLE_ANIMATION:-false}
- DISABLE_HIDDEN_POLICY=${DOCKER_ANDROID_DISABLE_HIDDEN_POLICY:-false}
- SKIP_AUTH=${DOCKER_ANDROID_SKIP_AUTH:-true}
- MEMORY=${DOCKER_ANDROID_MEMORY:-8192}
- CORES=${DOCKER_ANDROID_CORES:-4}
devices:
- "${DOCKER_ANDROID_KVM_DEVICE:-/dev/kvm}:/dev/kvm"
healthcheck:
test: ["CMD-SHELL", "adb devices 2>/dev/null | grep -q emulator"]
interval: 30s
timeout: 10s
retries: 5
start_period: 60s
deploy:
resources:
limits:
cpus: ${DOCKER_ANDROID_CPU_LIMIT:-2}
memory: ${DOCKER_ANDROID_MEMORY_LIMIT:-8G}
reservations:
cpus: ${DOCKER_ANDROID_CPU_RESERVATION:-1}
memory: ${DOCKER_ANDROID_MEMORY_RESERVATION:-4G}
devices:
- driver: nvidia
count: ${DOCKER_ANDROID_GPU_COUNT:-1}
capabilities: [gpu]
volumes:
docker_android_data:

View File

@@ -14,9 +14,6 @@ x-mongo: &mongo
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME:-root}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD:-password}
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE:-admin}
volumes:
- ./secrets/rs0.key:/data/rs0.key:ro
- mongo_data:/data/db
entrypoint:
- bash
- -c
@@ -49,6 +46,9 @@ services:
<<: *mongo
ports:
- "${MONGO_PORT_OVERRIDE_1:-27017}:27017"
volumes:
- mongo_data:/data/db
- ./secrets/rs0.key:/data/rs0.key:ro
mongo-init:
<<: *defaults
@@ -66,6 +66,8 @@ services:
MONGO_HOST: ${MONGO_HOST:-host.docker.internal}
volumes:
- ./secrets/rs0.key:/data/rs0.key:ro
extra_hosts:
- "host.docker.internal:host-gateway"
entrypoint:
- bash
- -c

View File

@@ -14,8 +14,6 @@ x-mongo: &mongo
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME:-root}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD:-password}
MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE:-admin}
volumes:
- ./secrets/rs0.key:/data/rs0.key:ro
entrypoint:
- bash
- -c
@@ -47,16 +45,25 @@ services:
<<: *mongo
ports:
- "${MONGO_PORT_OVERRIDE_1:-27017}:27017"
volumes:
- mongo1_data:/data/db
- ./secrets/rs0.key:/data/rs0.key:ro
mongo2:
<<: *mongo
ports:
- "${MONGO_PORT_OVERRIDE_2:-27018}:27017"
volumes:
- mongo2_data:/data/db
- ./secrets/rs0.key:/data/rs0.key:ro
mongo3:
<<: *mongo
ports:
- "${MONGO_PORT_OVERRIDE_3:-27019}:27017"
volumes:
- mongo3_data:/data/db
- ./secrets/rs0.key:/data/rs0.key:ro
mongo-init:
<<: *defaults
@@ -78,6 +85,8 @@ services:
MONGO_PORT_2: ${MONGO_PORT_OVERRIDE_2:-27018}
MONGO_PORT_3: ${MONGO_PORT_OVERRIDE_3:-27019}
MONGO_HOST: ${MONGO_HOST:-host.docker.internal}
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- ./secrets/rs0.key:/data/rs0.key:ro
entrypoint:
@@ -122,3 +131,8 @@ services:
reservations:
cpus: ${MONGO_REPLICA_INIT_CPU_RESERVATION:-0.50}
memory: ${MONGO_REPLICA_INIT_MEMORY_RESERVATION:-1024M}
volumes:
mongo1_data:
mongo2_data:
mongo3_data: