How to run React Native app on Android inside Docker

Alina Semenukha
LITSLINK
Published in
3 min readJan 13, 2023

Sometimes you need to run React Native app on Android inside Docker just to avoid local environmental pollution. Let’s find out how to do this.

First of all, you need to create a new React Native application. To do this run react-native init dockerAndroidRun on your terminal. Then open this project with any integrated development environment (IDE). Start server with yarn start and start your Android application with running yarn android — android script from your project package.json or you can start it with AndroidStudio .

Add Dockerfile to the root of your project with a following code

Note: you need to select base image with environment you need (second line of the code above).

Now add the docker-compose.yml to the root of your project and add the following code to it

To run Android inside Docker you need to have Docker Desktop installed and started on your machine.

Now in your project’s terminal run the following commands

docker build . && docker-compose build && docker-compose up

Note: if you happen to see an error below, please remove the current android simulator and create a new one using Android Studio.

To create an android simulator with Android Studio:

  1. Open Android Studio
  2. On the top menu select Tools => Device Manger

3. You will see Device Manager window. Press Create device button

4. In the opened window select device and press Next button.

5. In the next window select system image and press Next button.

6. In the next window verify your configuration and press Finish .

That is it! All sources are open and available on my GitHub repository.

--

--