Search code examples
dockercontainersusbadbportforwarding

ADB on docker container does not read Android device connected to host


So short story long, I want to containerise my Appium android automation tests. I have downloaded all the required tools on the container:

  • nvm
  • node
  • appium
  • uiautomator2
  • android-sdk
  • android-tools-adb
  • usbutils

Paths are all set and environment variables ANDROID_SDK_ROOT is also set.


The only missing thing here is to make the container access my host USB ports. I have no idea how to do this! I have tried to follow https://github.com/boot2docker/boot2docker/issues/707 but it did not work, as you can see this was 8 years ago and deprecated ! I also tried to run the container with the --privileged argument. ABD was not able to find the Android device when running abd devices. I read another blog, that says make sure to kill the ADB server on your host machine so that the ADB server on the container can access it, also did not work. A very great option which I think will definitely work as mentioned here https://github.com/boot2docker/boot2docker/issues/707 is to mount the usb directories in /dev to the container. But, I cannot find this directory /dev/bus/usb on my host. Is it under a different directory now?


How can I achieve this? Make ADB server on the Docker container to be able to access and read all Android devices which are connected on USB ports on MacOS host?


Solution

  • I was able to achieve this by setting an env variable in the docker file ENV ANDROID_ADB_SERVER_ADDRESS "host.docker.internal". This way it will connect to my host ADB server instead of creating a new one in the container.