docker容器配置ADB开发环境

docker容器配置ADB开发环境

创建 Docker 容器

1
2
3
4
5
# 1. 要求映射usb文件夹到docker /dev/bus/usb:/dev/bus/usb
docker run -it --privileged=true -v /dev/bus/usb:/dev/bus/usb -v /home/yanghuan/workspace/aiot_benchmark:/root/workspace --net=host --name=aiot_benchmark --hostname=aiot_benchmark ubuntu:20.04 /bin/bash

# 2. 安装android udev规则,此时 cat /etc/group 确保有plugdev用户组
apt-get install android-sdk-platform-tools-common

1681447491778.png

1
2
3
4
5
6
7
8
9
10
11
# 3.将当前用户加入plugindev用户组
usermod-a -G plugdev root
# 4. 关闭的退出容器
exit
# 5. 宿主机上重新登录docker
docker start aiot_benchmark
docker attach aiot_benchmark
# 6. 确保已加入用户组,并检查连接情况
id
lsusb
# 没有lsusb的,apt install usbutils

1681448105689.png

安装 Android SDK

安装 sdkmanager

参考sdkmanager文档中描述

  1. 从 Android Studio 下载页面中下载最新的“command line tools only”软件包,然后将其解压缩。

  2. 将解压缩的 cmdline-tools 目录移至您选择的新目录,例如 android_sdk。这个新目录就是您的 Android SDK 目录。

  3. 在解压缩的 cmdline-tools 目录中,创建一个名为 latest 的子目录。

  4. 将原始 cmdline-tools 目录内容(包括 lib 目录、bin 目录、NOTICE.txt 文件和 source.properties 文件)移动到新创建的 latest 目录中。现在,您就可以从这个位置使用命令行工具了。

  5. 加入环境变量

    1
    2
    echo "export PATH=$PATH:/root/android_sdk/cmdline-tools/latest/bin" >> /root/.bashrc
    source ~/.bashrc
  6. 安装 open jdk 11

    1
    apt-get install openjdk-11-jdk -y
  7. 安装 platfrom-tools 和其他包

    1
    2
    3
    # 设置代理
    export https_proxy="http://172.16.101.180:7890"
    sdkmanager --install "platform-tools" "platforms;android-29" "ndk;25.0.8775105"

1681449532864.png

  1. 设置 adb 环境变量

    1
    2
    echo "export PATH=$PATH:/root/android_sdk/platform-tools" >> /root/.bashrc
    source ~/.bashrc
  2. 连接设备(确保没有其他的 adb 服务了)
    1681450096396.png

Docker 配置桌面 + VNC Server

Docker 配置桌面 + VNC Server

面向docker hub构建

1
2
3
4
5
6
7
8
docker pull sheephuan/vnc4docker:ubuntu2004-xfce4-20220531

docker run --privileged -itd -p 22001:22 -p 15901:5901 --name ubuntu-xfce4 vnc-ubuntu2004:xcfe4 /usr/sbin/init

docker exec -it ubuntu-xfce4 /bin/bash

# vncserver 默认密码123456
vncserver :1 -localhost no

1654065658384.png

从零开始构建

构建Dokcer

1
2
3
4
5
6
7
docker pull ubuntu:focal-20200423

# -v hostdir:dockerdir
# 注意这样启动 无法正常使用systemctl命令
docker run -it -p 22001:22 -p 15902:5901 --name xfce4 ubuntu:focal-20200423 /bin/bash
#启动
docker exec -it huany /bin/bash

apt换源

1
2
3
4
5
# 备份
cp /etc/apt/sources.list /etc/apt/sources.list.bak
rm /etc/apt/sources.list
vim /etc/apt/sources.list

阿里云

https://developer.aliyun.com/mirror/ubuntu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

清华开源镜像站

https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 20.04 LTS
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
# 记得把https换成http
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

中科大

https://mirrors.ustc.edu.cn/help/ubuntu.html?highlight=ubuntu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 默认注释了源码仓库,如有需要可自行取消注释
deb http://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse

deb http://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse

deb http://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse

deb http://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

安装桌面环境 xfce4+tigervnc

安装

1
2
3
apt update
apt install xfce4 xfce4-goodies -y
apt install tigervnc-standalone-server -y

配置vnc

设置vnc密码
1
2
3
4
# 设置vnc密码
vncpasswd
# 输入两次密码
# 第三次的view-only password 输入 n 即可
设置vnc启动桌面
1
2
# 编写xstartup文件,
vim /root/.vnc/xstartup
1
2
3
4
5
#输入以下内容
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
exec startxfce4
1
2
# 设置启动权限
chmod u+x /root/.vnc/xstartup
设置vnc显示选项
1
2
3
4
5
6
# in /root/.vnc/config
# vim /root/.vnc/config
geometry=1920x1080
dpi=128


启动vnc
1
2
# -localhost no表示其他IP可以访问,否则只能本地访问
vncserver -localhost no
设置 VNC 为 系统服务(我没做)
1
vim /etc/systemd/system/vncserver@.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=simple
User=linuxize
PAMName=login
PIDFile=/home/%u/.vnc/%H%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill :%i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver :%i -geometry 1920x1080 -alwaysshared -fg
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

保存此文件

1
2
3
4
5
6
# 配置文件生效
systemctl daemon-reload
# 设为开机启动
systemctl enable vncserver@1.service
systemctl start vncserver@1.service
systemctl status vncserver@1.service

打包镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
docker commit xfce4 vnc-ubuntu2004:xcfe4

# 容器长传
docker tag vnc-ubuntu2004:xcfe4 sheephuan/vnc4docker:ubuntu2004-xfce4-20220531
docker login
docker push sheephuan/vnc4docker:ubuntu2004-xfce4-20220531

docker save -o vnc-ubuntu2004-xcfe4.tar vnc-ubuntu2004:xcfe4



# 在新服务载入
docker load --input vnc-ubuntu2004-xcfe4.tar

考虑学习写一个Dockerfile

问题

System has not been booted with systemd as init system (PID 1). Can’t operate.

1
docker run --privileged -itd -p 22004:22  -p 15904:5901 --name txfce4 vnc-ubuntu2004:xcfe4 /usr/sbin/init

Failed to exec default Terminal Emulator

1653997211716.png

https://blog.csdn.net/weixin_42912498/article/details/107162983

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×