简体   繁体   中英

Can't connect to host ADB from within docker container

Before this is my scenario an illustration of my environment to better understand my problem

在此处输入图片说明

I have a docker container running in my machine with the following docker-compose configuration

services: 
  addb-client:
    build:
     context: .
     dockerfile: Dockerfile
    ports:
      - 19000:19000
      - 19001:19001
      - 19002:19002
    tty: true
    volumes: 
      - ".:/code"

From my host I execute the following command

adb -a -P 5037 server nodaemon

And I go the following output

adb I 01-12 11:06:05  2493  2493 auth.cpp:437] adb_auth_init...
adb I 01-12 11:06:05  2493  2493 auth.cpp:412] adb_auth_inotify_init...
adb I 01-12 11:06:05  2493  2499 transport.cpp:295] emulator-5554: write thread spawning
adb I 01-12 11:06:05  2493  2498 transport.cpp:282] emulator-5554: read thread spawning
adb I 01-12 11:06:05  2493  2493 transport.cpp:1373] fetching keys for transport emulator-5554
adb I 01-12 11:06:05  2493  2493 auth.cpp:489] Calling send_auth_response
adb I 01-12 11:06:05  2493  2493 adb.cpp:114] emulator-5554: offlin

Then from within my docker container , I run

adb connect yyy.yyy.yyy.yyy

yyy.yyy.yyy.yyy being my android emulator address as in the picture

failed to connect to 'yyy.yyy.yyy.yyy:5555': Connection timed out

But I got timeout

I tried

adb connect xxx.xxx.xxx.xxx

But I got connection refused

Note:

1.Commands such as , from within the container

adb -H yyy.yyy.yyy.yyy devices

Works well.

I will appreciate any helps you can provide me. If any additional information is needed please let me know. Thanks.

This seems like a networking issue.... To access the host from within the docker container, you have 2 options:

  1. Access the ip of the docker bridge interface on the host

     $ docker run -ti busybox /bin/sh / # netstat -rn | grep ^0.0.0.0 | awk '{print $2}' 172.17.0.1 / # nc -vz 172.17.0.1 5037 172.17.0.1 (172.17.0.1:5037) open
  2. Add argument to the docker runtime to provide access from the container to the host via the 'localhost' keyword

    $ docker run -ti busybox /bin/sh / # nc -vz localhost 5037 ### NOT WORKING $ docker run -ti --net="host" busybox /bin/sh / # nc -vz localhost 5037 localhost (127.0.0.1:5037) open ### WORKING

The docker-compose equivalent is :

network_mode: host

If you get devices list typing adb devices on your host, and if you want to get the same list running the same command in the console on the container, I would give an advice trying port forwarding with ssh .

Please inspect this answer or this repo .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM