Connecting to a USB Android device in a Docker container via ADB
While I was trying the same, I ran into some other problems related to that, which I would like to share so that others may save their time:
Problem 1: lsusb was not installed in the container
In my case lsusb was not installed, so I installed it with the below command:
apt-get updateapt-get install usbutils
Problem 2: not able to see the device even after lsusb and ADB SDK installation
You need to restart your container with the -v
option, and yes don't forget to kill the ADB server as stated in one of the answers.
On the host:
adb-kill serverdocker run -ti -d --privileged -v /dev/bus/usb:/dev/bus/usb container_name
In case someone wanted do it from scratch, I have written a blog post on it:
This doesn't answer the exact question you were asking, but does address what you were trying to accomplish - connecting to an android device connected to a docker host from an adb client running inside a docker container. I'm including this for anyone trying to accomplish the same thing (like I was).
The adb client supports a -H
option which tells it where to find the adb server to connect to. Docker supports the hostname "host.docker.internal" which always maps to the IP address of the docker host. Assuming your device is connected to the docker host, you can do the following to get your containerized adb client to connect to the adb server running on the docker host:
adb -H host.docker.internal devices
Accomplishes the goal without having to mount the USB ports.
Reference: https://developer.android.com/studio/command-line/adb
Update: I recently learned that host.docker.internal is only supported on Docker for Mac in versions 18.0 and above.