React-Native on Android using Docker

254 views Asked by At

I am new to React-Native and Docker. I am trying to run React-Native development enviroment in Docker. I followed this tutorial here, but when starting the docker container with docker-compose up it fails with:

error Failed to install the app. Make sure you have an Android emulator running or a device connected

I have a "Nexus 5 API 30" emulator set up and running on my host using Android Studio. If I understood this correctly the line entrypoint: ['bash', '-c', 'adb connect localhost:5555 && yarn android'] is supposed to connect to the emulator on my local machine. I tried to configure the emulator to listen on port 5555 but when going to Android Studio > Device Manager > Edit The AVD I want to use > Advanced Settings. There is no way to configure the Port.

this is my dockerfile:

# pull base image
FROM reactnativecommunity/react-native-android:v12.0

# Adds user and group node
RUN groupadd --gid 1000 node \
  && useradd --uid 1000 --gid node --shell /bin/bash --create-home node

# set our node environment, either development or production
# defaults to production, compose overrides this to development on build and run
ARG NODE_ENV=development
ENV NODE_ENV $NODE_ENV

# default to port 19006 for node, and 19001 and 19002 (tests) for debug
ARG PORT=5037
ENV PORT $PORT

# install global packages
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH /home/node/.npm-global/bin:$PATH

# due to default /opt permissions we have to create the dir with root and change perms
RUN mkdir /MyApp && chown node:node /MyApp
WORKDIR /MyApp 
ENV PATH /MyApp/node_modules/.bin:$PATH

USER node
RUN yarn install

and this is my docker-compose.yaml:

version: '3'

services:
  myapp:
    build:
      context: .
    tty: true
    network_mode: 'host'
    ports:
      - '5037:5037'
    volumes:
      - ./:/MyApp/:delegated
      - notused:/./node_modules
    healthcheck:
      disable: true
    entrypoint: ['bash', '-c', 'adb connect localhost:5555 && yarn android']
volumes:
  notused:
0

There are 0 answers