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

前端 未结 6 1056
鱼传尺愫
鱼传尺愫 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 19:11

    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.

提交回复
热议问题