Skip to main content
  1. All Posts/

Build Your Own Cloud Phone

Aaron
Author
Aaron
I only know that I know nothing.
Table of Contents

Preface
#

There are many cloud phone providers on the market today. While they’re generally stable, putting all your data in someone else’s hands doesn’t feel very secure. Who knows if they’re recording your screen during operations?

There’s an open-source project on GitHub1 called Redroid2 that lets you run Android containers using Docker. I’ve been using it for a long time and it’s very stable.

Prerequisites
#

You’ll need a server. Both AMD64 and ARM64 architectures are supported.

Supported operating systems (click to view deployment instructions for each):

If you’re a beginner, I recommend Ubuntu, Arch Linux, or NixOS. Ubuntu requires loading kernel modules, while Arch Linux and NixOS just need a switch to the zen kernel.

Installation
#

This section only covers the three operating systems mentioned above. For other systems, refer to the official documentation.

Ubuntu
#

I recommend not using the latest Ubuntu version, as there may be various minor issues. I’ve tested versions 20.04 and 22.04 without any problems. Run the following commands to load the kernel modules:

sudo apt install linux-modules-extra-`uname -r`
sudo modprobe binder_linux devices="binder,hwbinder,vndbinder"
sudo modprobe ashmem_linux

Install Docker3 using the one-click script:

curl -sSL https://get.docker.com/ | sh

Or install Docker and Docker Compose using the package manager:

sudo apt install docker docker-compose

Arch Linux
#

Install the linux-zen kernel:

# Update system
sudo pacman -Syu
# Install linux-zen kernel
sudo pacman -S linux-zen linux-zen-headers
# Update GRUB boot configuration
sudo grub-mkconfig -o /boot/grub/grub.cfg
# Reboot
sudo reboot
# Verify kernel version (should show "zen")
uname -r

Install Docker and Docker Compose using the package manager:

sudo pacman -S docker docker-compose

NixOS
#

Install the linux-zen kernel:

# Add to /etc/nixos/configuration.nix
boot.kernelPackages = pkgs.linuxPackages_zen
# Rebuild and apply
sudo nixos-rebuild switch
# Reboot
sudo reboot
# Verify kernel version (should show "zen")
uname -r

Install Docker and Docker Compose:

# Add to /etc/nixos/configuration.nix
virtualisation.docker.enable = true;
# docker-compose
environment.systemPackages = with pkgs; [ docker-compose ];
# Rebuild and apply
sudo nixos-rebuild switch

Running the Redroid Container
#

Direct Launch
#

sudo docker run -itd --rm --privileged \
    --pull always \
    -v ~/data:/data \
    -p 5555:5555 \
    redroid/redroid:11.0.0-latest

Using Docker Compose
#

# docker-compose.yaml
version: "3"
services:
  redroid:
    stdin_open: true
    tty: true
    privileged: true
    pull_policy: always
    volumes:
      - ~/data:/data
    ports:
      - 5555:5555
    image: redroid/redroid:11.0.0-latest
# Start the container
sudo docker-compose up -d

Additional Notes
#

Connecting to the Device
#

You can operate Android with your mouse by installing adb4 and scrcpy5.

On macOS and Linux, install android-platform-tools and scrcpy using your package manager:

# macOS
brew install --cask android-platform-tools scrcpy
# Debian & Ubuntu
sudo apt install android-platform-tools scrcpy
# Arch Linux
sudo pacman -S android-platform-tools scrcpy
# NixOS
environment.systemPackages = with pkgs; [ android-tools scrcpy ];

If you want to control Android from a web browser, try the ws-scrcpy project.

If you don’t want to set up the environment yourself, you can use my pre-built image: aaronyes/ws-scrcpy.

Run directly:

sudo docker run --name ws-scrcpy -d -p 8000:8000 aaronyes/ws-scrcpy

Or use Docker Compose:

version: "3"
services:
  ws-scrcpy:
    container_name: ws-scrcpy
    ports:
      - 8000:8000
    image: aaronyes/ws-scrcpy

After starting, connect to Android using adb:

sudo docker exec ws-scrcpy adb connect ip:5555

If using Docker Compose, you can combine both services:

version: "3"
services:
  redroid:
    container_name: redroid
    stdin_open: true
    tty: true
    privileged: true
    pull_policy: always
    volumes:
      - ~/data:/data
    ports:
      - 5555:5555
    image: redroid/redroid:11.0.0-latest

  ws-scrcpy:
    container_name: ws-scrcpy
    ports:
      - 8000:8000
    image: aaronyes/ws-scrcpy

Now you can connect using the container name:

docker exec ws-scrcpy adb connect redroid:5555

Installing Apps Without an App Store
#

  1. Use adb to install apps. Download the APK file on your computer, then run adb install <path-to-apk>

  2. Alternatively, install Via Browser (very small, lightweight, and ad-free), then use it to download and install other apps

Installing Magisk
#

Refer to the following guide:

GMS Support
#

Refer to the following documentation:

References
#