Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect to specific device after startup #48

Open
GuyKh opened this issue May 7, 2024 · 8 comments
Open

Connect to specific device after startup #48

GuyKh opened this issue May 7, 2024 · 8 comments

Comments

@GuyKh
Copy link

GuyKh commented May 7, 2024

A question, more than an issue.

Currently, I'm starting the container via docker-compose:

  adb:
    ports:
      - 5037:5037
    privileged: true
    volumes:
      - ${HOME}/docker/adbd:/root/.android
      - /dev/bus/usb:/dev/bus/usb
    container_name: adbd
    image: devicefarmer/adb
    restart: unless-stopped

But every time afterwards, I have to run this to connect to 192.168.1.123

docker exec -it adbd adb connect 192.168.1.123:5555

Is there a way to run a command after the container is up so I wouldn't have to do it manually?

@benedikt-bartscher
Copy link

+1 for this, very useful feature. We probably want the adb connect to be run again on disconnection, or at least with a schedule

@koral--
Copy link
Member

koral-- commented Jan 20, 2025

My first thought is to use wait option. Like this: docker compose up … --wait && docker exec ….

@benedikt-bartscher
Copy link

benedikt-bartscher commented Jan 20, 2025

i wrote a script which wraps the original container entrypoint - works fine

@koral-- koral-- closed this as completed Jan 20, 2025
@GuyKh
Copy link
Author

GuyKh commented Jan 21, 2025

Ummmm... @koral-- how come this is closed? I don't feel this was solved.

@benedikt-bartscher - could you share the script?

@koral-- koral-- reopened this Jan 21, 2025
@koral--
Copy link
Member

koral-- commented Jan 21, 2025

I answered here: #48 (comment)
Doesn't that solve the issue?

@GuyKh
Copy link
Author

GuyKh commented Jan 21, 2025

@koral-- but this is merely doing this manually.
docker compose up -d && docker exec adb connect...

This is not a solution and not even a workaround...

@koral--
Copy link
Member

koral-- commented Jan 21, 2025

OK got it.

@benedikt-bartscher
Copy link

benedikt-bartscher commented Jan 21, 2025

@GuyKh it's not perfect but it works

.env

ADB_HOSTS=10.10.10.10:5555

docker-compose.yml

  adb:
    container_name: adb
    image: devicefarmer/adb:latest@sha256:ad5ac763b6d9f45650b5463b916cfc79ab624268533b9c92632368ec743e18a4
    restart: unless-stopped
    command: /adb-entrypoint.sh
    environment:
      - ADB_HOSTS=${ADB_HOSTS}
    volumes:
      - "/dev/bus/usb:/dev/bus/usb"
      - "./adb/android:/root/.android/"
      - "./adb/adb-connect.sh:/adb-connect.sh"
      - "./adb/adb-entrypoint.sh:/adb-entrypoint.sh"
    privileged: true

adb-entrypoint.sh

#!/bin/sh
# runs adb.sh in background and then runs the initial entrypoint of docker-adb

# run adb.sh which periodically connects to our devices (ADB_HOSTS) in the background
./adb-connect.sh &

# original entrypoint from Dockerfile (https://github.com/DeviceFarmer/docker-adb/blob/master/Dockerfile)
# CMD ["adb", "-a", "-P", "5037", "server", "nodaemon"]
adb -a -P 5037 server nodaemon

adb-connect.sh

#!/bin/sh

echo "Waiting for adb server to start"
sleep 10
echo "Starting adb connect script"

# infinite loop which runs `adb connect` for all entries in ADB_HOSTS
while true; do
  for host in $ADB_HOSTS; do
    echo "Connecting to $host"
    adb connect "$host"
  done
  sleep 30
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants