Remotely access ADB server located inside a Docker container

1.5k Views Asked by At

I have a Docker container on a host A, which exports a SSH service on port 5022. E.g. If I want to connect to the container, I typically do ssh -p 5022 user@hostA.

In the Docker container, I have an ADB server (Android Debug Bridge) which is running on port 5037 (that's the default port). For example, I can run adb devices in the container to list all the Android devices and emulators which are connected.

I would like to do that, but remotely, from host B. So, from host B, I would like adb devices to be redirected to the ADB in my remote docker container.

I have tried to setup a tunnel such as this: ssh -L 9999:127.0.0.1:5037 -N -T -p 5022 user@hostA and then adb -H 127.0.0.1 -P 9999 devices but it does not work :( and says error: protocol fault (no status) and channel 2: open failed: connect failed: Connection refused by the tunnel.

Tunnel:

bash $ ssh -L 9999:127.0.0.1:5037 -N -T -p 5022 user@hostA user@hostA's password: channel 2: open failed: connect failed: Connection refused

ADB:

bash $ adb -H 127.0.0.1 -P 9999 devices error: protocol fault (no status)

Edit 1:

I also tried (unsuccessfully): ssh -N -T -L 9999:172.17.0.11:5037 -p 5022 user@host where 172.17.0.11 is the local IP address of the docker container on host. And then adb -H 127.0.0.1 -P 9999 devices still unhappy error: protocol fault (no status).

The output of docker ps is:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS cef3d4daf9bc cryptax/android-re "/usr/bin/supervisord" 23 hours ago Up 23 hours 0.0.0.0:5037->5037/tcp, 0.0.0.0:5554->5554/tcp, 0.0.0.0:5900->5900/tcp, 5555/tcp, 0.0.0.0:5022->22/tcp androidre

The output of docker inspect androidre contains:

"HostConfig": {
...
    "PortBindings": {
                "22/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "5022"
                    }
                ],
                "5037/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "5037"
                    }
                ],
                "5554/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "5554"
                    }
                ],
                "5900/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "5900"
                    }
                ]
            },
...
 "Config": {
            "Hostname": "cef3d4daf9bc",
...
            "ExposedPorts": {
                "22/tcp": {},
                "5037/tcp": {},
                "5554/tcp": {},
                "5555/tcp": {},
                "5900/tcp": {}
            },
...

"NetworkSettings": {
            "Bridge": "",
            "HairpinMode": false,
...
            "Ports": {
                "22/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "5022"
                    }
                ],
                "5037/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "5037"
                    }
                ],
                "5554/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "5554"
                    }
                ],
                "5555/tcp": null,
                "5900/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "5900"
                    }
                ]
            },
            "Gateway": "172.17.0.1",
...
            "IPAddress": "172.17.0.11",
            "IPPrefixLen": 16,
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.11",
...
                }
0

There are 0 best solutions below