简体   繁体   English

在 Docker-Compose 上创建的 docker 容器上运行 ADB

[英]Run ADB on docker container created on Docker-Compose

I'm trying to start a JAVA server (SPRING) container which runs ADB commands.我正在尝试启动运行 ADB 命令的 JAVA 服务器(SPRING)容器。 I have created a docker-compose (I start many containers together..) file but I can't see the devices connected on the machine.我创建了一个 docker-compose(我一起启动了许多容器......)文件,但我看不到机器上连接的设备。 I found solutions on how to do this as mention here but it doesn't uses docker compose.我找到了有关如何执行此操作的解决方案,如此处所述,但它不使用 docker组合。

Note: I use Docker for windows 10.注意:我将 Docker 用于 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!谢谢!

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我不知道你是否已经解决了这个问题,我测试了你的 docker-compose 并设法运行没有问题添加到卷

- /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.无需将 adb 端口添加到文件中。

I hope it helped someone.我希望它对某人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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