'react native docker container using vs code to publish to android emulator on host OS

I am trying to run a react native docker container on vs code. I am able to run my code. However, the container is not able to detect the android emulator running on my host machine.

I followed along in this tutorial course:

https://code.visualstudio.com/docs/remote/containers & https://github.com/microsoft/vscode-react-native

On running

npx react-native run-android however, I get an error message that my emulator is not running. error Failed to install the app. Make sure you have an Android emulator running or a device connected. Run CLI with --verbose flag for more details. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

My devcontainer.json:-

{
    "name": "React Native Android Container",
  
    // Sets the run context to one level up instead of the .devcontainer folder.
    "context": "..",
  
    // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
    "dockerFile": "Dockerfile",
  
    "runArgs": [
        "--privileged", // give all capabilities to a container, in other words, the container can then do almost everything that the host can do
        "--net",
        "host", // forwarding all host machine ports
        "-v",
        "/dev/bus/usb:/dev/bus/usb" // mount connected USB devices to a container
      ],
    
  
    "settings": {
      // This will ignore your local shell user setting for Linux since shells like zsh are typically
      // not in base container images. You can also update this to an specific shell to ensure VS Code
      // uses the right one for terminals and tasks. For example, /bin/bash (or /bin/ash for Alpine).
      "terminal.integrated.shell.linux": null
    },
  
    // Add the IDs of extensions you want to be installed when the container is created in the array below.
    "extensions": ["msjsdiag.vscode-react-native"]
  }

the runArgs "host" is supposed to forward all ports. I think I need a similar argument in the reverse direction?



Solution 1:[1]

Check the permissions for android/gradlew. Can check the permissions using the below command:

stat -c "%a %n" android/gradlew

The permissions should be 755. If not change the permissions to 755 inside your app root folder.

chmod 755 android/gradlew

then run react-native run-android

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ashok