From 17131a32f15f6ea1e1c9b00531db989432caddc3 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 6 Dec 2018 21:27:56 -0600 Subject: [PATCH] attemps to shove anbox into docker --- 2018-09-16-anbox-archlinux.md | 131 ++++++++++++++++++++++++++++++++++ Dockerfile | 76 ++++++++++++++++++++ Dockerfile_alt | 14 ++++ Dockerfile_alt_config | 16 +++++ Dockerfile_config | 24 +++++++ scripts/anbox-bridge.sh | 1 + 6 files changed, 262 insertions(+) create mode 100644 2018-09-16-anbox-archlinux.md create mode 100644 Dockerfile create mode 100644 Dockerfile_alt create mode 100644 Dockerfile_alt_config create mode 100644 Dockerfile_config diff --git a/2018-09-16-anbox-archlinux.md b/2018-09-16-anbox-archlinux.md new file mode 100644 index 0000000..162713a --- /dev/null +++ b/2018-09-16-anbox-archlinux.md @@ -0,0 +1,131 @@ +# install + +# use + +#automation + +# sources +https://github.com/anbox/anbox/issues/305 + + + +To run in the arch (I used yaourt) I first installed the system kernel headers for the DKMS. + +"yaourt -s linux-headers" (I found the version compatible with my my kernel - 4.10.12-1-MANJARO) +Then I compiled the anbox with the following packages: + +"aur/anbox-git" +"aur/anbox-image" +"aur/anbox-modules-dkms-git" +I started systemd networks services (for internet to work in apps) + +"sudo systemctl start systemd-resolved.service" +"sudo systemctl start systemd-networkd.service" +And started the container-manager service + +"sudo systemctl start anbox-container-manager.service" +I added the host driver in /usr/lib/systemd/user/anbox-session-manager.service by changing the line: + +From "ExecStart=/usr/bin/anbox session-manager" +To "ExecStart=/usr/bin/anbox session-manager --gles-driver=host" +I started the user service: + +"systemctl --user start anbox-session-manager.service" +Then it worked! + + +# Create a portable android via docker + +load modules before compiling? +## host os +ashmem and binder + +[cryosphere@sd_arch anbox]$ lsmod | grep bind +binder_linux 118784 60 +[cryosphere@sd_arch anbox]$ lsmod | grep ashmem +ashmem_linux 16384 9 + + +## build it + +git clone here or docker pull this + +## download a pre-build android image + +wget https://build.anbox.io/android-images/2018/06/11/android_amd64.img + + +### run it + +docker run -it --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --privileged dmeyerson:anbox /bin/bash + + +docker run -it --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" -v /mnt/store/android_images:/var/lib/anbox/ --privileged dmeyerson:anbox /bin/bash + +docker run -it --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" -v /mnt/store/android_images:/var/lib/anbox/ --privileged -v /tmp/.X11-unix:/tmp/.X11-unix dmeyerson:anbox /bin/bash + +## sessopm , +## GUI apps on docker + +https://medium.com/@SaravSun/running-gui-applications-inside-docker-containers-83d65c0db110 + + + + +## +# troubleshooting +### debug +docker run -it --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --privileged dmeyerson:anbox /bin/bash run -it --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --privileged -v /tmp/.X11-unix:/tmp/.X11-unix local:anbox /bin/bash + + + + +### access to kernel modules +root@22650413b559:/anbox/build# anbox session-manager + 2018-10-21 17:23:19] [session_manager.cpp:130@operator()] Failed to start as either binder or ashmem kernel drivers are not loaded + +on the container - verify ashmem and binder +root@90b5b5028fd2:/anbox/build# anbox system-info | grep bind + binder: false +root@90b5b5028fd2:/anbox/build# anbox system-info | grep ash + ashmem: false + +make sure you are running with --privileged flag and binder + ashmem are loaded in host OS + +## runtime env issues +[cryosphere@sd_arch anbox]$ docker run -it --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --privileged -v /tmp/.X11-unix:/tmp/.X11-unix local:anbox /bin/bash +root@sd_arch:/anbox/build# anbox session-manager +[ 2018-10-21 18:07:30] [daemon.cpp:61@Run] No runtime directory specified + +reading https://github.com/anbox/anbox/issues/597 +make sure the flag is present -e XDG_RUNTIME_DIR={} arg +attemped ad-hoc from w/in the container +root@sd_arch:/anbox/build# export XDG_RUNTIME_DIR=/run/user/1000 # same as hose os? + + +## socket error +[ 2018-10-21 18:13:17] [daemon.cpp:61@Run] Failed to connect to socket /run/anbox-container.socket: No such file or directory +reading https://github.com/anbox/anbox/issues/123 + indicates that we need to start the container manager first? + +## current state +docker run -it --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" -v /mnt/store/android_images:/var/lib/anbox/ --privileged -e XDG_RUNTIME_DIR=/run/user/1000 -e ANBOX_LOG_LEVEL='trace' local:anbox /bin/bash + +anbox container-manager --daemon --privileged --data-path=/var/lib/anbox & + +root@sd_arch:/anbox/build# anbox session-managerls +[ 2018-10-21 22:01:42] [Renderer.cpp:168@initialize] Using a surfaceless EGL context +[ 2018-10-21 22:01:42] [Renderer.cpp:251@initialize] Successfully initialized EGL +[ 2018-10-21 22:01:42] [service.cpp:41@Service] Successfully acquired DBus service name +[ 2018-10-21 22:01:42] [client.cpp:49@start] Failed to start container: Failed to start + + ## next + https://github.com/mviereck/x11docker + + +# current state +docker run -it --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" -v /mnt/store/android_images:/var/lib/anbox/ --privileged -e XDG_RUNTIME_DIR=/run/user/1000 -e ANBOX_LOG_LEVEL='trace' local:base_anbox /bin/bash + +# two layer build process +docker build -t local:base_anbox ./ +docker build -t local:config_anbox -f ./Dockerfile_config ./ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4ff7dce --- /dev/null +++ b/Dockerfile @@ -0,0 +1,76 @@ +#!/bin/sh +FROM ubuntu:18.04 + +RUN apt-get update && apt-get install -y \ + build-essential \ + cmake \ + cmake-data \ + cmake-extras \ + debhelper \ + dbus \ + dbus-x11 \ + git \ + google-mock \ + libboost-dev \ + libboost-filesystem-dev \ + libboost-log-dev \ + libboost-iostreams-dev \ + libboost-program-options-dev \ + libboost-system-dev \ + libboost-test-dev \ + libboost-thread-dev \ + libcap-dev \ + libegl1-mesa-dev \ + libgles2-mesa-dev \ + libglib2.0-dev \ + libglm-dev \ + libgtest-dev \ + liblxc1 \ + libproperties-cpp-dev \ + libprotobuf-dev \ + libsdl2-dev \ + libsdl2-image-dev \ + libsystemd-dev \ + lxc-dev \ + pkg-config \ + protobuf-compiler \ + iproute2 \ + iptables \ + kmod \ + x11-apps + # apt-get clean + +WORKDIR /anbox + +# cleanup() { +# # In cases where anbox comes directly from a checked out Android +# # build environment we miss some symlinks which are present on +# # the host and don't have a valid git repository in that case. +# clear + + +#if [ -d .git ] ; then +# admp +#ls git clean -fdx . +# git reset --hard +# ad fi +# } +# cleanup +#COPY CMakeLists.txt CMakeLists.txt +#COPY src src +COPY . /anbox +RUN mkdir build || rm -rf build/* +RUN ls +WORKDIR /anbox/build +RUN cmake .. +RUN VERBOSE=1 make -j10 +RUN VERBOSE=1 make test +RUN make install +ENV ANBOX_LOG_LEVEL='trace' +#RUN export $(dbus-launch) +# VERBOSE=1 make test +# todo - use wget to get a version controlled android image. +#COPY android.img /var/lib/anbox/android.img +#ENTRYPOINT ["anbox container-manager --daemon --privileged --data-path=/var/lib/anbox"] + +#docker run -it --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" -v /mnt/store/android_images:/var/lib/anbox/ --privileged -v /tmp/.X11-unix:/tmp/.X11-unix local:anbox /bin/bash \ No newline at end of file diff --git a/Dockerfile_alt b/Dockerfile_alt new file mode 100644 index 0000000..2d04338 --- /dev/null +++ b/Dockerfile_alt @@ -0,0 +1,14 @@ +#!/bin/sh +FROM ubuntu:18.04 + +RUN apt-get update && apt-get install -y \ + build-essential \ + software-properties-common \ + kmod \ + snapd \ + sudo +RUN add-apt-repository -y ppa:morphis/anbox-support +RUN apt update +RUN apt install snapd +#apt install anbox-modules-dkms +#docker run -it --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" -v /mnt/store/android_images:/var/lib/anbox/ --privileged -v /tmp/.X11-unix:/tmp/.X11-unix local:fast_anbox /bin/bash \ No newline at end of file diff --git a/Dockerfile_alt_config b/Dockerfile_alt_config new file mode 100644 index 0000000..e4fa711 --- /dev/null +++ b/Dockerfile_alt_config @@ -0,0 +1,16 @@ + $ sudo add-apt-repository ppa:morphis/anbox-support + $ sudo apt update + $ sudo apt install anbox-modules-dkms + +``` + $ sudo modprobe ashmem_linux + $ sudo modprobe binder_linux +``` + +``` + $ snap install --devmode --beta anbox + + + ``` + $ snap info anbox +``` \ No newline at end of file diff --git a/Dockerfile_config b/Dockerfile_config new file mode 100644 index 0000000..d26c616 --- /dev/null +++ b/Dockerfile_config @@ -0,0 +1,24 @@ +#!/bin/sh +FROM local:anbox + +# VERBOSE=1 make test +# todo - use wget to get a version controlled android image. +#COPY android.img /var/lib/anbox/android.img +#ENTRYPOINT ["anbox container-manager --daemon --privileged --data-path=/var/lib/anbox"] +#export $(dbus-launch) +service dbus start + +#run as service +anbox container-manager --daemon --privileged --data-path=/var/lib/anbox + +export $(dbus-launch) + +./anbox-bridge.sh start + +export XDG_RUNTIME_DIR=/run/user/1000 +anbox session-manager + +# #ip link add dev "${BRIDGE}" type bridge +# # logs +# 12 cat /var/lib/anbox/logs/container.log +# 13 cat /var/lib/anbox/logs/console.log diff --git a/scripts/anbox-bridge.sh b/scripts/anbox-bridge.sh index 7cf2cea..e796023 100755 --- a/scripts/anbox-bridge.sh +++ b/scripts/anbox-bridge.sh @@ -96,6 +96,7 @@ start() { set -e # set up the anbox network + echo ${BRIDGE} [ ! -d "/sys/class/net/${BRIDGE}" ] && ip link add dev "${BRIDGE}" type bridge # if we are run from systemd on a system with selinux enabled,