Skip to content

Connect Each Device to a separate container - ADB fails when a second device attached #172

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

Open
idekterev opened this issue Feb 20, 2025 · 1 comment

Comments

@idekterev
Copy link

idekterev commented Feb 20, 2025

The Readme states you can use something like the following to connect each device to a separate container:

$ docker run -d -p 4723:4723 --device /dev/bus/usb/XXX/YYY:/dev/bus/usb/XXX/YYY -v ~/.android:/root/.android --name device1 appium/appium

For some reason, when running a container using the described method to '--device /dev/bus/usb/XXX/YYY:/dev/bus/usb/XXX/YYY', the moment a second device is plugged in, ADB stops inside the first container. This basically means that multiple appium containers cannot run as adb fails the moment there is more than one.

Host: Ubuntu 22.04
Docker version 27.5.1, build 9f9e405

Steps:

  1. One device connected via USB, lsusb lists it as /dev/bus/usb/002/042.

  2. Docker run command:
    adb kill-server && docker run --rm -p 4723:4723 --device=/dev/bus/usb/002/042 appium/appium:local

  3. Check adb devices in container 1: running "docker exec -it CONTAINERID adb devices" correctly lists one device connected.

  4. Plug in second ADB device via USB

  5. repeat step 3 (check adb devices in container): adb to fail inside the first container:

* daemon not running; starting now at tcp:5037
ADB server didn't ACK
Full server startup log: /tmp/adb.1300.log
Server had pid: 57
--- adb starting (pid 57) ---
02-19 10:00:10.534    57    57 I adb     : main.cpp:63 Android Debug Bridge version 1.0.41
02-19 10:00:10.534    57    57 I adb     : main.cpp:63 Version 35.0.2-12147458
02-19 10:00:10.534    57    57 I adb     : main.cpp:63 Installed as /opt/android/platform-tools/adb
02-19 10:00:10.534    57    57 I adb     : main.cpp:63 Running on Linux 6.11.0-17-generic (x86_64)
02-19 10:00:10.534    57    57 I adb     : main.cpp:63
02-19 10:00:10.535    57    57 I adb     : auth.cpp:416 adb_auth_init...
02-19 10:00:10.535    57    57 I adb     : auth.cpp:220 User key '/home/androidusr/.android/adbkey' does not exist...
02-19 10:00:10.535    57    57 I adb     : auth.cpp:64 generate_key(/home/androidusr/.android/adbkey)...
02-19 10:00:10.735    57    57 I adb     : auth.cpp:152 loaded new key from '/home/androidusr/.android/adbkey' with fingerprint 80F96A80CCB1DD12A7534A67492D8E938101295E6896B8D9E28BF2411F156798
02-19 10:00:10.735    57    57 I adb     : auth.cpp:391 adb_auth_inotify_init...
02-19 10:00:10.735    57    57 I adb     : udp_socket.cpp:170 AdbUdpSocket fd=15
02-19 10:00:10.735    57    57 I adb     : udp_socket.cpp:274 SetMulticastOutboundInterface for index=44
02-19 10:00:10.735    57    57 I adb     : udp_socket.cpp:533 bind endpoint=0.0.0.0:5353
02-19 10:00:11.546    57    57 E adb     : usb_libusb.cpp:598 failed to open device: No such device (it may have been disconnected)
02-19 10:00:11.546    57    57 I adb     : transport.cpp:1153 00002401181035280063: connection terminated: failed to open device: No such device (it may have been disconnected)

* failed to start daemon
adb: failed to check server version: cannot connect to daemon

Is this a bug, or does anyone have any ideas as to why this is happening?

@DeeFlone
Copy link

DeeFlone commented Mar 7, 2025

@idekterev,
Edit: Found solution nmeum/android-tools#153
Just set environment variable ADB_LIBUSB=0

Faced same issue. Despite specifying /dev/bus/usb/001/004 (with android serial 12345) docker container tries to make adb connect to another device with serial 54321 which should be at /dev/bus/usb/001/028 and apparently fails because it isn't mounted to this container.

~/docker$ docker exec -it appium_device2 adb devices
 daemon not running; starting now at tcp:5037
ADB server didn't ACK
Full server startup log: /tmp/adb.0.log
Server had pid: 59
--- adb starting (pid 59) ---
03-07 12:47:29.967    59    59 I adb     : main.cpp:63 Android Debug Bridge version 1.0.41
03-07 12:47:29.967    59    59 I adb     : main.cpp:63 Version 35.0.2-12147458
03-07 12:47:29.967    59    59 I adb     : main.cpp:63 Installed as /opt/android/platform-tools/adb
03-07 12:47:29.967    59    59 I adb     : main.cpp:63 Running on Linux 6.1.0-26-amd64 (x86_64)
03-07 12:47:29.967    59    59 I adb     : main.cpp:63 
03-07 12:47:29.971    59    59 I adb     : auth.cpp:416 adb_auth_init...
03-07 12:47:29.972    59    59 I adb     : auth.cpp:152 loaded new key from '/root/.android/adbkey' with fingerprint C771789A90BEDD9D9EC232AB0B8255FE5E4FAC16A7F55257A4C8B17AC225D9AC
03-07 12:47:29.972    59    59 I adb     : auth.cpp:391 adb_auth_inotify_init...
03-07 12:47:29.974    59    59 I adb     : udp_socket.cpp:170 AdbUdpSocket fd=13
03-07 12:47:29.974    59    59 I adb     : udp_socket.cpp:274 SetMulticastOutboundInterface for index=163
03-07 12:47:29.974    59    59 I adb     : udp_socket.cpp:533 bind endpoint=0.0.0.0:5353
03-07 12:47:29.981    59    59 I adb     : transport.cpp:1710 fetching keys for transport 12345
03-07 12:47:29.981    59    59 I adb     : auth.cpp:468 Calling send_auth_response
03-07 12:47:29.997    59    59 I adb     : auth.cpp:435 Calling send_auth_publickey
03-07 12:47:30.982    59    59 E adb     : usb_libusb.cpp:598 failed to open device: No such device (it may have been disconnected)
03-07 12:47:30.982    59    59 I adb     : transport.cpp:1153 54321: connection terminated: failed to open device: No such device (it may have been disconnected)

 failed to start daemon
adb: failed to check server version: cannot connect to daemon

/dev/bus/usb devices in container

~/docker$ docker exec -it appium_device2 ls -la /dev/bus/usb/*
ls: cannot access '/dev/bus/usb/002': No such file or directory
/dev/bus/usb/001:
total 0
drwxr-xr-x 2 root root        60 Mar  7 12:46 .
drwxr-xr-x 3 root root        60 Mar  7 12:46 ..
crwxrwxrwx 1 root plugdev 189, 3 Mar  7 12:47 004

/dev/bus/usb devices on host

~/docker$ ls -la /dev/bus/usb/*
/dev/bus/usb/001:
total 0
drwxr-xr-x  3 root root        160 Mar  7 15:09 .
drwxr-xr-x  4 root root         80 Mar  7 12:07 ..
crw-rw-r--  1 root root    189,  0 Mar  7 12:30 001
crw-rw-r--  1 root root    189,  1 Mar  7 12:30 002
crw-rw-r--  1 root root    189,  2 Mar  7 12:30 003
crwxrwxrwx+ 1 root plugdev 189,  3 Mar  7 13:03 004
drwxr-xr-x  2 root root         40 Mar  7 12:03 012
crwxrwxrwx+ 1 root plugdev 189, 27 Mar  7 15:09 028

/dev/bus/usb/002:
total 0
drwxr-xr-x 2 root root       60 Mar  7 12:07 .
drwxr-xr-x 4 root root       80 Mar  7 12:07 ..
crw-rw-r-- 1 root root 189, 128 Mar  7 12:30 001

Disconnecting 028 device from host makes docker exec -it appium_device2 adb devices command work as expected.
Have no idea how to connect each device to a separate container and get working containers.

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

2 participants