Connecting to a USB Android device in a Docker container via ADB

前端 未结 6 1063
鱼传尺愫
鱼传尺愫 2020-12-04 18:15

I have created a Docker image which contains the Android SDK and am trying to expose my Android phone in a container running this image. So I used the --privileged

6条回答
  •  时光说笑
    2020-12-04 18:55

    Update:

    I ended up using --privileged and -v to map the whole of /dev/bus/usb and patching adb to accept one environment variable to specify the root USB device tree - /dev/bus/usb/001 etc.

    This allowed us to use different USB busses for different containers for different groups of the same phone, and another environment variable patch allowed different VID:PID lists for different types of phone.


    We're trying to allocate different USB buses to different Docker containers running TeamCity clients.

    Each container needs ANDROID_ADB_SERVER_PORT setting to a different port (because we're not using segregated networking).

    The host machine can't run adbd, because only one adbd can talk to a phone at any given time.

    Each container gets one of the /dev/bus/usb/xxx directories, so we can plug phones into particular containers.

    We have to synchronise the /dev/bus/usb/xxx directory every few seconds, to allow hot-plugging and reboots - just a shell loop on the host that runs tar cf devxxx.tar /dev/bus/usb/xxx, docker cp to transfer it, then docker exec to untar inside the container's /tmp, diff to detect nodes to delete, and mv -n to move new nodes in.


    In fact, because we're running on Linux, we can probably just set up udev scripts, per Howto run a script when a USB device is pluged in.

提交回复
热议问题