Run Android Emulator on Docker

How to build and run Android Emulator on a Docker container, run locally on MacBook. Assumption Docker is installed. I learned about Docker from this GitHub tutorial. In this tutorial, we will create and run an Android Emulator inside a Docker container.

1. Pull the Android Docker images.

a. Open Docker application on MacBook.

b. Open a new terminal and enter below commands:

//Pulls android-sdk image
docker pull thyrlian/android-sdk
//Pulls android-sdk-vnc image
docker pull thyrlian/android-sdk-vnc
//Runs android sdk on container
docker run -it — rm -v $(pwd)/sdk:/sdk thyrlian/android-sdk bash -c 'cp -a $ANDROID_HOME/. /sdk'

2. Modified below command to use your file ssh key path “../../ssh/id_rsa.pub”

docker run -d -p 5901:5901 -p 2222:22 -p 5037:5037 -v $(pwd)/sdk:/opt/android-sdk -v /Users/asandoval/.ssh/id_rsa.pub:/root/.ssh/authorized_keys thyrlian/android-sdk-vnc

3. Open new terminal and SSH into container. Use below command to install Android emulator components

ssh root@0.0.0.0 -p 2222 //enter your SSH id_rsa key password
ssh to Docker container

Enter below commands to download Android emulator components:

sdkmanager "platform-tools" "platforms;android-24" "emulator"
sdkmanager "system-images;android-24;default;armeabi-v7a"

Enter below commands to create new Android Emulator:

avdmanager create avd -n emuTest -k "system-images;android-24;default;armeabi-v7a"
emulator -avd emuTest -noaudio -no-boot-anim -gpu off
Command create Android emulator API 24

4. The Android emulator is starting inside Docker container

Now VNC to the container. With VNC you are able to see the emulator. You will have an android emulator running on your virtual machine “container”

a. On MacBook open application “Screen Sharing”.

b. Enter below:

vnc://0.0.0.0:5901 
(password: android)
5. Open new terminal and enter below ADB commands.
$adb kill-server
$adb connect 0.0.0.0:5037
$adb logcat
$adb assembleReleaseGloogeBuild
$adb install -r /PATH-to-your-APK/./.

Since the sdk container is persisted on host machine (`-v $(pwd)/sdk:/sdk`), we don’t need to install the emulator packages after the first run,We just need to open terminal and enter below command.

//Runs android sdk on container
docker run -it — rm -v $(pwd)/sdk:/sdk thyrlian/android-sdk bash -c ‘cp -a $ANDROID_HOME/. /sdk’

The Docker container running the Android emulator keeps running until you stop/kill docker container. Below Docker commands shows how to stop docker container:

docker ps -a
docker rm -f {container ID}


The goal: is to be able to build and run Android emulators on the cloud, and be able to run android Espresso test on cloud. For some reason android emulator performance is a bit poor. ARM emulator is slow, X86 is preferred, but that needs a physical Linux machine with KVM enabled.

Good tutorial about Android Docker

TODO: Learned how to deploy docker container to AWS.


Let me know if you have any questions, thanks. -Andres