How to dockerize Android Emulator and run it without any prerequisite softwares?

An image uploaded to Strapi
An image uploaded to Strapi

Amir Alam

Technology

Downloading and installing the android emulators is a big headache as we have to download and set up tons of stuff manually like, JAVA, ANDROID TOOLS, etc. To avoid these manual steps there is a new technology that will solve your problem and rescue you from it.

Containers

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings.

Docker

It used to be that when you wanted to run a web application, you bought a server, installed Linux, set up a LAMP stack, and ran the app. If your app got popular, you practiced good load balancing by setting up a second server to ensure the application wouldn't crash from too much traffic.

So by reading these 2 paragraphs you would become familiar with the words containers and docker right?

Let's Run The Emulator!

Now to run a container you first need a Docker Image, A docker image is just a file in which steps are written in it one by one and when we try to execute those steps it all executes in an isolated environment and becomes a container.

Google has an official Docker Script to run Android Emulators, so you don't need to write the images from scratch all by yourselves.

Requirements

Well yeah, I said you don't need to install any software, but you should at least have Docker and ADB installed for once. Docker for running images and ADB for detecting virtual devices by which you can use that emulator on your host device or can also access it remotely.

Run The Emulator Just by Terminal

Open a terminal and paste these codes.

carbon (2).png docker run
-e ADBKEY="$(cat ~/.android/adbkey)"
--device /dev/kvm
--publish 8554:8554/tcp
--publish 5555:5555/tcp
us-docker.pkg.dev/android-emulator-268719/images/30-google-x64:30.1.2

This will download the image and run it, you will not need to do any further steps.

After the container is ready, you can connect to your device just by typing this to terminal

carbon (1) (1).png

adb connect localhost:5555

After it you can see the available devices through ‘ADB Devices’ command

Final Words

Running an emulator on Linux has become easy as you just need to execute a simple one line of code and your device will automatically start the emulator. But keep in mind that this tutorial will only work on Linux devices in which KVM is enabled. In windows PC it won't work as no Nested KVM is available in it. Thank You!

An image uploaded to Strapi
Amir Alam

To run the emulator without the need of installing jdk, sdk, and other required drivers and software On Linux. Here is the tutorial to run any android emulator in a virtual environment using docker.