Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run ADB on docker container created on Docker-Compose

I'm trying to start a JAVA server (SPRING) container which runs ADB commands. I have created a docker-compose (I start many containers together..) file but I can't see the devices connected on the machine. I found solutions on how to do this as mention here but it doesn't uses docker compose.

Note: I use Docker for windows 10.

This is what I wrote down in the meantime:

version: '3.8'
services:
  java-server:
  image: openjdk:8
  privileged: true       <----- I thought this should help
  pid: "host"
  ports:
    - target: 80
      published: 80
      protocol: tcp
      mode: host
    - target: 5037           <----- I thought this should help, expose the adb port
      published: 5037
      protocol: tcp
      mode: host
  networks:
  - default

volumes:
 - "/C/Users/user/StudioProjects/pc-java-app/apache2-entrypoint.sh:/var/lib/mysql/data/apache2-entrypoint.sh"
 - "/C/Users/user/StudioProjects/pc-java-app/target/java-server-0.1.25.6.jar:/var/lib/mysql/data/java-server-0.1.25.6.jar"

command: >
    bash -c "apt-get update && apt-get install -y android-tools-adb && /bin/bash && cd /var/lib/mysql/data/ && ls -l && adb devices && java -jar java-server-0.1.25.6.jar"

networks:
  mt-network:
  driver: bridge

volumes:
  my-db:

and getting:

# adb devices
 List of devices attached

#

Thank you!

like image 797
Itai.S. Avatar asked Feb 09 '26 21:02

Itai.S.


1 Answers

I do not know if you have already solved this problem, I tested this your docker-compose and managed to run without problems adding to the volumes

- /dev/bus/usb:/dev/bus/usb

So the container will have access to the folder of your local machine.

No need to add the adb port to the file.

I hope it helped someone.

like image 182
Edson Vitor Avatar answered Feb 12 '26 16:02

Edson Vitor