Files

5.7 KiB

ChunYu Full Stack Docker Setup

Complete Docker deployment for ChunYu platform: Django backend, React frontend, and Android emulator.

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                        Docker Network                            │
│  ┌──────────────┐    ┌──────────────┐    ┌──────────────────┐  │
│  │   Backend     │◄──►│   Frontend   │    │  Android (KVM)   │  │
│  │   :8000       │    │   :8080      │    │  redroid :5555   │  │
│  │   Daphne      │    │   Nginx      │    │  + ADB           │  │
│  └──────────────┘    └──────────────┘    └──────────────────┘  │
│         ▲                                      │                │
│         │          ┌──────────────┐            │                │
│         └──────────┤   MySQL      │────────────┘                │
│                    │   (external) │                              │
│                    └──────────────┘                              │
└─────────────────────────────────────────────────────────────────┘
         │
    ┌────┴────┐
    │  MuMu   │  (optional, host-side emulator)
    │  ADB    │
    └─────────┘

Quick Start

Prerequisites

  • Docker Desktop (Windows) with WSL2 or Hyper-V
  • KVM enabled (for Android emulator)
  • 8GB+ RAM recommended

1. Clone and Configure

# Copy environment file
cp docker.env.example docker.env

# Edit docker.env with your settings

2. Build and Start

# Build APK and start all services
./start.sh --build-apk

# Or start without building APK
./start.sh

3. Access Services

Service URL Description
Backend API http://localhost:8000 Django REST API
Frontend http://localhost:8080 React SPA
Swagger Docs http://localhost:8080/swagger/ API Documentation
ADB localhost:5555 Android Debug Bridge

Android Emulator Options

Option A: Docker Android (Redroid) - Default

Uses redroid/redroid image with KVM acceleration.

Requirements:

  • KVM enabled in BIOS
  • /dev/kvm accessible

Start:

docker compose up -d

Connect ADB:

adb connect localhost:5555
adb devices

Option B: MuMu Emulator on Host

Use MuMu emulator running on your host machine.

Steps:

  1. Start MuMu emulator on your host
  2. Enable ADB in MuMu settings (usually port 5555 or 7555)
  3. Connect ADB: adb connect <mumu-ip>:5555
  4. Start services: ./start.sh --mumu

MuMu Network Configuration:

  • MuMu uses 10.0.2.2 to reach host localhost
  • Backend should be accessible at http://10.0.2.2:8000 from MuMu

Option C: Build APK Only

Build APK and install manually on any emulator.

docker build -t chunyu-apk-builder -f android/Dockerfile.build-apk .
docker create --name temp-apk chunyu-apk-builder
docker cp temp-apk:/output/app-debug.apk ./app-debug.apk
docker rm temp-apk

# Install on any emulator/device
adb install app-debug.apk

Configuration

Backend Environment Variables

Variable Default Description
MYSQL_PASSWORD - MySQL password
REDIS_PASSWORD - Redis password
DJANGO_SECRET_KEY - Django secret key
DJANGO_DEBUG True Debug mode
DJANGO_ALLOWED_HOSTS localhost Allowed hosts
CORS_ALLOWED_ORIGINS - CORS origins

Android App Configuration

The Android app reads backend URL from:

  1. local.properties (build-time)
  2. /data/local/tmp/chunyu/backend_host (runtime, set by Docker entrypoint)

Default backend URL: http://192.168.5.7:8000/

Troubleshooting

Android Emulator Won't Start

# Check KVM
ls -la /dev/kvm

# Check Docker has access
docker run --rm --device /dev/kvm ubuntu ls -la /dev/kvm

# Check redroid logs
docker compose logs android

ADB Connection Issues

# Restart ADB server
adb kill-server
adb start-server

# Connect to Docker Android
adb connect localhost:5555

# Connect to MuMu
adb connect 127.0.0.1:5555

Backend Can't Reach Database

Ensure MySQL at 192.168.5.7:3306 is accessible from Docker:

docker run --rm mysql:8 mysql -h 192.168.5.7 -u root -p

Production Deployment

For production, use the existing docker-compose.yml without Android:

docker compose up -d backend frontend

File Structure

.
├── docker-compose.yml          # Main compose file
├── docker.env                  # Environment variables
├── start.sh                    # Quick start script
├── android/
│   ├── Dockerfile              # Redroid Android emulator
│   ├── Dockerfile.build-apk    # APK builder
│   ├── entrypoint.sh           # Android container entrypoint
│   └── apks/                   # APK storage
├── chunyu_project/             # Django backend
│   └── Dockerfile
├── chunyu_project_react/       # React frontend
│   └── Dockerfile
└── nginx-docker.conf           # Nginx config for Docker