├── .github ├── PULL_REQUEST_TEMPLATE │ └── pull_request_template.md └── workflows │ ├── ghcr.yaml │ └── main.yaml ├── Dockerfile ├── LICENSE ├── README.md ├── docker-compose.yml ├── docs └── screenshot-20200410.png ├── hack ├── install-kmod.sh └── translate-dockerfile-runopt-directive.sh ├── kube └── aind.yaml └── src ├── anbox-container-manager-pre.sh ├── anbox-container-manager.service ├── docker-2ndboot.sh ├── patches └── anbox │ └── README.md └── unsudo /.github/PULL_REQUEST_TEMPLATE/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # Contribution guide 2 | (You may remove this contribution guide texts from your PR) 3 | 4 | * Sign your commits with your real name and valid e-mail address, using `git commit -a -s` . 5 | i.e. Make sure to include the `Signed-off-by: ...` line in your commit. 6 | * Do not add non-free packages . 7 | -------------------------------------------------------------------------------- /.github/workflows/ghcr.yaml: -------------------------------------------------------------------------------- 1 | # Adopted from https://github.com/docker/metadata-action/tree/v3.3.0#basic 2 | # (Apache License 2.0) 3 | name: GHCR 4 | 5 | on: 6 | push: 7 | branches: 8 | - 'master' 9 | tags: 10 | - 'v*' 11 | pull_request: 12 | branches: 13 | - 'master' 14 | 15 | jobs: 16 | ghcr: 17 | runs-on: ubuntu-20.04 18 | steps: 19 | - name: Checkout 20 | uses: actions/checkout@v2 21 | - name: Docker meta 22 | id: meta 23 | uses: docker/metadata-action@v3 24 | with: 25 | images: ghcr.io/${{ github.repository }} 26 | - name: Login to GHCR 27 | if: github.event_name != 'pull_request' 28 | uses: docker/login-action@v1 29 | with: 30 | registry: ghcr.io 31 | username: ${{ github.repository_owner }} 32 | password: ${{ secrets.GITHUB_TOKEN }} 33 | - name: Build and push 34 | uses: docker/build-push-action@v2 35 | with: 36 | context: . 37 | push: ${{ github.event_name != 'pull_request' }} 38 | tags: ${{ steps.meta.outputs.tags }} 39 | labels: ${{ steps.meta.outputs.labels }} 40 | -------------------------------------------------------------------------------- /.github/workflows/main.yaml: -------------------------------------------------------------------------------- 1 | name: Main 2 | on: [push, pull_request] 3 | jobs: 4 | test-main: 5 | runs-on: ubuntu-18.04 6 | steps: 7 | - uses: actions/checkout@v2 8 | # host info 9 | - run: docker info 10 | - run: docker version 11 | - run: cat /proc/cpuinfo 12 | # test 13 | - run: ./hack/translate-dockerfile-runopt-directive.sh < Dockerfile | DOCKER_BUILDKIT=1 docker build -f - -t ghcr.io/aind-containers/aind:local . 14 | - run: sudo ./hack/install-kmod.sh 15 | - run: docker run -td --name aind --privileged -p 5900:5900 -p 8080:8080 -e "WEBMODE=1" -v /lib/modules:/lib/modules:ro ghcr.io/aind-containers/aind:local 16 | - run: timeout 60 sh -exc "until docker exec aind pgrep -f org.anbox.appmgr; do sleep 10; done" 17 | # diagnosis 18 | - run: docker exec aind ps -ef 19 | if: always() 20 | - run: docker logs aind 21 | if: always() 22 | - run: docker exec aind cat /var/lib/anbox/logs/console.log 23 | if: always() 24 | # TODO: capture screenshot and upload as an artifact 25 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # this dockerfile can be translated to `docker/dockerfile:1-experimental` syntax for enabling cache mounts: 2 | # $ ./hack/translate-dockerfile-runopt-directive.sh < Dockerfile | DOCKER_BUILDKIT=1 docker build -f - . 3 | 4 | ARG BASE=ubuntu:20.04 5 | 6 | # Sep 26, 2020 7 | ARG ANBOX_COMMIT=170f1e029e753e782c66bffb05e91dd770d47dc3 8 | 9 | # ARG ANDROID_IMAGE=https://build.anbox.io/android-images/2018/07/19/android_amd64.img 10 | # Mirror 11 | ARG ANDROID_IMAGE=https://github.com/AkihiroSuda/anbox-android-images-mirror/releases/download/snapshot-20180719/android_amd64.img 12 | # https://build.anbox.io/android-images/2018/07/19/android_amd64.img.sha256sum 13 | ARG ANDROID_IMAGE_SHA256=6b04cd33d157814deaf92dccf8a23da4dc00b05ca6ce982a03830381896a8cca 14 | 15 | FROM ${BASE} AS anbox 16 | ENV DEBIAN_FRONTEND=noninteractive 17 | RUN apt-get update && \ 18 | apt-get install -qq -y --no-install-recommends \ 19 | build-essential \ 20 | ca-certificates \ 21 | cmake \ 22 | cmake-data \ 23 | cmake-extras \ 24 | debhelper \ 25 | dbus \ 26 | git \ 27 | google-mock \ 28 | libboost-dev \ 29 | libboost-filesystem-dev \ 30 | libboost-log-dev \ 31 | libboost-iostreams-dev \ 32 | libboost-program-options-dev \ 33 | libboost-system-dev \ 34 | libboost-test-dev \ 35 | libboost-thread-dev \ 36 | libcap-dev \ 37 | libegl1-mesa-dev \ 38 | libexpat1-dev \ 39 | libgles2-mesa-dev \ 40 | libglm-dev \ 41 | libgtest-dev \ 42 | liblxc1 \ 43 | libproperties-cpp-dev \ 44 | libprotobuf-dev \ 45 | libsdl2-dev \ 46 | libsdl2-image-dev \ 47 | libsystemd-dev \ 48 | lxc-dev \ 49 | pkg-config \ 50 | protobuf-compiler \ 51 | python2 52 | RUN git clone --recursive https://github.com/anbox/anbox /anbox 53 | WORKDIR /anbox 54 | ARG ANBOX_COMMIT 55 | RUN git pull && git checkout ${ANBOX_COMMIT} && git submodule update --recursive 56 | COPY ./src/patches/anbox /patches 57 | # `git am` requires user info to be set 58 | RUN git config user.email "nobody@example.com" && \ 59 | git config user.name "AinD Build Script" && \ 60 | if [ -f /patches/*.patch ]; then git am /patches/*.patch && git show --summary; fi 61 | # runopt = --mount=type=cache,id=aind-anbox,target=/build 62 | RUN ./scripts/build.sh && \ 63 | cp -f ./build/src/anbox /anbox-binary 64 | 65 | FROM ${BASE} AS android-img 66 | ENV DEBIAN_FRONTEND=noninteractive 67 | RUN apt-get update && \ 68 | apt-get install -qq -y --no-install-recommends \ 69 | ca-certificates curl 70 | ARG ANDROID_IMAGE 71 | ARG ANDROID_IMAGE_SHA256 72 | RUN curl --retry 10 -L -o /android.img $ANDROID_IMAGE \ 73 | && echo $ANDROID_IMAGE_SHA256 /android.img | sha256sum --check 74 | 75 | FROM ${BASE} 76 | ENV DEBIAN_FRONTEND=noninteractive 77 | RUN apt-get update && \ 78 | apt-get install -qq -y --no-install-recommends \ 79 | # base system 80 | ca-certificates curl iproute2 jq kmod socat \ 81 | # lxc 82 | iptables lxc \ 83 | # anbox deps 84 | libboost-log1.71.0 libboost-thread1.71.0 libboost-program-options1.71.0 libboost-iostreams1.71.0 libboost-filesystem1.71.0 libegl1-mesa libgles2-mesa libprotobuf-lite17 libsdl2-2.0-0 libsdl2-image-2.0-0 \ 85 | # squashfuse 86 | squashfuse fuse3 \ 87 | # adb 88 | adb \ 89 | # systemd 90 | dbus dbus-user-session systemd systemd-container systemd-sysv \ 91 | # X11 92 | xvfb x11vnc \ 93 | # noVNC 94 | websockify novnc \ 95 | # WM 96 | fvwm xterm \ 97 | # debug utilities 98 | busybox figlet file strace less && \ 99 | # ... 100 | useradd --create-home --home-dir /home/user --uid 1000 -G systemd-journal user && \ 101 | curl -L -o /docker-entrypoint.sh https://raw.githubusercontent.com/AkihiroSuda/containerized-systemd/6ced78a9df65c13399ef1ce41c0bedc194d7cff6/docker-entrypoint.sh && \ 102 | chmod +x /docker-entrypoint.sh 103 | # apk-pre.d is for pre-installed apks, /apk.d for the mountpoint for user-specific apks 104 | RUN mkdir -p /apk-pre.d /apk.d && \ 105 | curl -L -o /apk-pre.d/FDroid.apk https://f-droid.org/FDroid.apk && \ 106 | curl -L -o /apk-pre.d/firefox.apk https://ftp.mozilla.org/pub/mobile/releases/68.9.0/android-x86_64/en-US/fennec-68.9.0.en-US.android-x86_64.apk && \ 107 | chmod 444 /apk-pre.d/* 108 | COPY --from=android-img /android.img /aind-android.img 109 | COPY --from=anbox /anbox-binary /usr/local/bin/anbox 110 | COPY --from=anbox /anbox/scripts/anbox-bridge.sh /usr/local/share/anbox/anbox-bridge.sh 111 | COPY --from=anbox /anbox/data/ui /usr/local/share/anbox/ui 112 | RUN ldconfig 113 | ADD src/anbox-container-manager-pre.sh /usr/local/bin/anbox-container-manager-pre.sh 114 | ADD src/anbox-container-manager.service /lib/systemd/system/anbox-container-manager.service 115 | RUN systemctl enable anbox-container-manager 116 | ADD src/unsudo /usr/local/bin 117 | ADD src/docker-2ndboot.sh /home/user 118 | 119 | ENV WEBMODE 0 120 | # Usage: docker run --rm --privileged -v /:/host --entrypoint bash ghcr.io/aind-containers/aind -exc "cp -f /install-kmod.sh /host/aind-install-kmod.sh && cd /host && chroot . /aind-install-kmod.sh" 121 | ADD hack/install-kmod.sh / 122 | VOLUME /var/lib/anbox 123 | ENTRYPOINT ["/docker-entrypoint.sh", "unsudo"] 124 | EXPOSE 5900 125 | EXPOSE 8080 126 | HEALTHCHECK --interval=15s --timeout=10s --start-period=60s --retries=5 \ 127 | CMD ["pgrep", "-f", "org.anbox.appmgr"] 128 | CMD ["/home/user/docker-2ndboot.sh"] 129 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # :warning: Deprecated in favor of ReDroid 2 | 3 | As of April 2021, AinD is deprecated in favor of [ReDroid](https://github.com/remote-android/redroid-doc). 4 | 5 | While Anbox/AinD has got stuck in Android 7.1, ReDroid supports very recent Android versions: 8.1, 9, 10, 11, and Android S (12). 6 | 7 | - - - 8 | # AinD: Android (Anbox) in Docker 9 | 10 | AinD launches Android apps in Docker, by nesting [Anbox](https://anbox.io/) containers inside Docker. 11 | 12 | Unlike VM-based similar projects, AinD can be executed on IaaS instances without support for nested virtualization. 13 | 14 | GHCR: `ghcr.io/aind-containers/aind` 15 | 16 | :warning: Docker Hub image [`aind/aind`](https://hub.docker.com/r/aind/aind) is no longer updated. Please use `ghcr.io/aind-containers/aind` image on GHCR. 17 | 18 | ## Purposes 19 | * Anti-theft (see [FAQ](#faq)) 20 | * Android compatibility (via cloud) for iOS and Windows tablets 21 | 22 | ### Non-goals 23 | * Cloud gaming 24 | 25 | ## Screenshots 26 | 27 | ```console 28 | $ docker ps -a 29 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 30 | 950e3fa7d320 aind "/docker-entrypoint.…" 7 minutes ago Up 7 minutes 0.0.0.0:5900->5900/tcp aind 31 | $ docker exec aind ps -ef | tail -n 20 32 | 101023 323 138 0 11:18 pts/2 00:00:00 /system/bin/sdcard -u 1023 -g 1023 -m -w /data/media emulated 33 | 110020 347 154 0 11:18 pts/2 00:00:00 com.android.systemui 34 | 101001 397 154 0 11:18 pts/2 00:00:00 com.android.phone 35 | user 403 154 0 11:18 pts/2 00:00:00 com.android.settings:CryptKeeper 36 | user 448 154 0 11:18 pts/2 00:00:00 com.android.settings 37 | 110009 531 154 0 11:18 pts/2 00:00:00 android.ext.services 38 | 110032 546 154 0 11:18 pts/2 00:00:00 com.android.deskclock 39 | 110015 577 154 0 11:18 pts/2 00:00:00 com.android.provision 40 | 110047 583 154 0 11:18 pts/2 00:00:00 com.android.smspush 41 | 110000 615 154 0 11:18 pts/2 00:00:00 org.anbox.appmgr 42 | 110011 642 154 0 11:18 pts/2 00:00:00 com.android.managedprovisioning 43 | 110008 657 154 0 11:18 pts/2 00:00:00 android.process.media 44 | 110003 675 154 0 11:18 pts/2 00:00:00 com.android.providers.calendar 45 | 110002 694 154 0 11:18 pts/2 00:00:00 android.process.acore 46 | 110027 744 154 0 11:18 pts/2 00:00:00 com.android.calendar 47 | 110028 765 154 0 11:18 pts/2 00:00:00 com.android.camera2 48 | 110034 784 154 0 11:18 pts/2 00:00:00 com.android.email 49 | 110037 807 154 0 11:18 pts/2 00:00:00 com.android.gallery3d 50 | 110013 822 154 0 11:18 pts/2 00:00:00 com.android.onetimeinitializer 51 | root 1003 0 0 11:25 ? 00:00:00 ps -ef 52 | ``` 53 | 54 | ![docs/screenshot.png](docs/screenshot-20200410.png) 55 | 56 | ## Quick start 57 | Tested on Ubuntu 19.10 (Kernel 5.3). 58 | May not work on other distros. 59 | If `modprobe ashmem_linux` or `modprobe binder_linux` fails, see https://github.com/anbox/anbox-modules . 60 | 61 | ```bash 62 | sudo modprobe ashmem_linux 63 | sudo modprobe binder_linux 64 | ``` 65 | 66 | ### Docker 67 | #### VNC 68 | ```bash 69 | docker run -td --name aind --privileged -p 5900:5900 -v /lib/modules:/lib/modules:ro ghcr.io/aind-containers/aind 70 | docker exec aind cat /home/user/.vnc/passwdfile 71 | ``` 72 | 73 | > **NOTE**: `--privileged` is required for nesting an Anbox (LXC) inside Docker. But you don't need to worry too much because Anbox launches "unprivileged" LXC using user namespaces. You can confirm that all Android processes are running as non-root users, by executing `docker exec aind ps -ef`. 74 | 75 | Wait for 10-20 seconds until Android processes are shown up in `docker exec aind ps -ef`, and then connect to `5900` via `vncviewer`. 76 | The VNC password is stored in `/home/user/.vnc/passwdfile`. The password file can be also overridden by `docker run -v /your/own/passwdfile:/home/user/.vnc/passwdfile:ro` . 77 | 78 | If the application manager doesn't shown up on the VNC screen, try `docker run ...` several times (FIXME). Also make sure to check `docker logs aind`. 79 | 80 | #### Web mode (noVNC) 81 | To run the container with [noVNC](https://novnc.com/) support, the environment variable `WEBMODE` can be set with the following command: 82 | 83 | ```bash 84 | docker run -td --name aind --privileged -p 8080:8080 -e "WEBMODE=1" -v /lib/modules:/lib/modules:ro ghcr.io/aind-containers/aind 85 | docker exec aind cat /home/user/.vnc/passwdfile 86 | ``` 87 | 88 | The container will be accessible via the browser at http://localhost:8080/vnc.html 89 | 90 | ### Docker Compose 91 | 92 | To bring the container up simply run 93 | ``` 94 | docker-compose up -d 95 | ``` 96 | the vnc password can be gotten with 97 | ``` 98 | docker-compose exec aind cat /home/user/.vnc/passwdfile 99 | ``` 100 | you can check how far it is with 101 | ``` 102 | docker-compose exec aind ps -ef 103 | ``` 104 | 105 | ### Kubernetes 106 | 107 | ```bash 108 | kubectl apply -f kube/aind.yaml 109 | kubectl port-forward service/aind 5900 110 | ``` 111 | 112 | The manifest contains the kernel module installer as `initContainers`. 113 | 114 | The manifest is known to work on: 115 | - Google Kubernetes Engine (GKE) 1.16.8-gke.8 (ubuntu) [Apr 14, 2020] 116 | - Kubernetes 1.16.8, Ubuntu 18.04.4, Kernel 5.3.0-1012-gke, Docker 19.03.2 117 | - n2-standard-8 118 | - Google Kubernetes Engine (GKE) 1.16.8-gke.8 (ubuntu\_containerd) [Apr 14, 2020] 119 | - Kubernetes 1.16.8, Ubuntu 18.04.4, Kernel 5.3.0-1012-gke, containerd 1.2.10 120 | - n2-standard-8 121 | - Azure Kubernetes Service (AKS) 1.17.3 [Apr 14, 2020] 122 | - Kubernetes 1.17.3, Ubuntu 16.04.6, Kernel 4.15.0-1071-azure, MS-Moby 3.0.10+azure 123 | - Standard DS2 v2 124 | - kind 0.7.0 [Apr 14, 2020] 125 | - Kubernetes 1.17.0, Ubuntu 19.10, Kernel 5.3.0-46-generic, containerd 1.3.2 126 | - **NOTE**: Requires `docker exec kind-control-plane mount -o remount,rw /sys` 127 | 128 | ## Tips 129 | 130 | ### Troubleshooting 131 | 132 | * `docker logs aind` 133 | * `docker exec -it aind systemctl status anbox-container-manager` 134 | * `docker exec -it aind ps -ef` 135 | * `docker exec -it aind cat /var/lib/anbox/logs/console.log` 136 | 137 | ### adb 138 | 139 | ```bash 140 | docker exec -it aind adb shell 141 | ``` 142 | 143 | To run adb on the host: 144 | 145 | ``` 146 | socat TCP-LISTEN:5037,reuseaddr,fork 'EXEC:docker exec -i aind "socat STDIO TCP-CONNECT:localhost:5037"' & 147 | adb connect localhost:5037 148 | adb shell 149 | ``` 150 | 151 | ## Apps 152 | 153 | ### Pre-installed Apps 154 | * Firefox 155 | * F-Droid 156 | * Misc accessories like Clock and Calculator 157 | 158 | ### Installing apk packages 159 | 160 | APK files mounted as `/apk.d/*.apk` are automatically installed on start up. 161 | 162 | You can also use [F-Droid](https://f-droid.org/). 163 | To use F-Droid, enable "Settings" -> "Security" -> "Allow installation of apps from unknown sources". 164 | 165 | ## FAQ 166 | ### Isn't encrypting the phone with strong passcode enough for anti-theft? Why do we need aind? 167 | People in the real world are likely to set weak passcode like "1234" (or finger pattern), because they want to open email/phone/twitter/maps/payment apps in just a few seconds. 168 | 169 | aind is expected to be used in conjunction with encryption of the client device, and to be used only for sensitive apps, with a passcode that is stronger than the passcode of the client device itself. 170 | 171 | ## TODOs 172 | * Map different UID range per containers 173 | * Better touch screen experience 174 | * Redirect camera, notifications, ... 175 | 176 | ## Similar projects 177 | * [Anbox](https://anbox.io/): Desktop only and single-user/single-instance only. aind is built using Anbox. 178 | * [Android container in Chrome OS](https://chromium.googlesource.com/chromiumos/platform2/+/master/arc/container-bundle/): ChromeOS/ChromiumOS-only 179 | * [Docker-Android](https://github.com/budtmo/docker-android): VM-based 180 | * [kubedroid](https://github.com/kubedroid/kubedroid): VM-based 181 | * [Anbox Cloud](https://anbox-cloud.io/): Proprietary 182 | * [Intel Celadon in Container (CIC)](https://github.com/projectceladon/device-intel-cic): [Proprietary](https://github.com/projectceladon/vendor-intel-cic/blob/9b91758a3fa0a6530910d0ada8e99816aa17195d/README) 183 | 184 | ## License 185 | * aind itself (e.g. Dockerfile, Kubernetes manifests, and start-up scripts) is licensed under the terms of [the Apache License, Version 2.0](./LICENSE). 186 | * The Anbox patches ([`./src/patches/anbox/*.patch`](./src/patches/anbox)) are licensed under the terms of [the GNU General Public License, Version 3](https://github.com/anbox/anbox/blob/master/COPYING.GPL), corresponding to [Anbox](https://github.com/anbox/anbox) itself. 187 | 188 | ### Binary image 189 | * The `ghcr.io/aind-containers/aind` image on GitHub Container Registry (built from [`./Dockerfile`](./Dockerfile)) contains the binaries of several free software. 190 | * Anbox (`/usr/local/bin/anbox`): [the GNU General Public License, Version 3](https://github.com/anbox/anbox/blob/master/COPYING.GPL) 191 | * Firefox (`/apk-pre.d/fennec-*.apk`): [the Mozilla Public License 2](https://www.mozilla.org/en-US/about/legal/eula/) 192 | * F-Droid (`/apk-pre.d/FDroid.apk`): [the GNU General Public License, Version 3](https://gitlab.com/fdroid/fdroidclient/-/blob/master/LICENSE) 193 | * Android image (`/android.img`, fetched from https://build.anbox.io/): see https://source.android.com/setup/start/licenses . For build instruction, see https://github.com/anbox/anbox/blob/master/docs/build-android.md 194 | * For other packages, see `/usr/share/doc/*/copyright` . 195 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | aind: 4 | image: 'ghcr.io/aind-containers/aind' 5 | privileged: true 6 | tty: true 7 | environment: 8 | - WEBMODE=1 9 | ports: 10 | - '5900:5900' 11 | - '8080:8080' 12 | volumes: 13 | - '/lib/modules:/lib/modules:ro' 14 | - 'dot-vnc:/home/user/.vnc' 15 | volumes: 16 | dot-vnc: 17 | -------------------------------------------------------------------------------- /docs/screenshot-20200410.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aind-containers/aind/e037ca29a823591bde32753460740a1c6a472b77/docs/screenshot-20200410.png -------------------------------------------------------------------------------- /hack/install-kmod.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Install ashmem and binder kernel modules from https://github.com/anbox/anbox-modules . 3 | # Must be executed on the host. 4 | set -eux -o pipefail 5 | if [ $(id -u) != 0 ]; then 6 | echo >&2 "must be executed as root" 7 | exit 1 8 | fi 9 | set +e 10 | /sbin/modprobe ashmem_linux 11 | /sbin/modprobe binder_linux 12 | set -e 13 | if [ -e /dev/ashmem ]; then 14 | if grep binder /proc/filesystems; then 15 | echo "ashmem and binderfs are already enabled. Skipping installing modules." 16 | exit 0 17 | fi 18 | if [ -e /dev/binder ]; then 19 | echo "ashmem and binder (classic) are already enabled. Skipping installing modules." 20 | exit 0 21 | fi 22 | fi 23 | 24 | if command -v apt-get >/dev/null 2>&1; then 25 | apt-get update 26 | ( 27 | source /etc/os-release 28 | if [[ $ID = "ubuntu" || $ID_LIKE =~ "ubuntu" ]]; then 29 | apt-get install -q -y dkms git linux-headers-generic 30 | else 31 | apt-get install -q -y dkms git linux-headers-amd64 32 | fi 33 | ) 34 | elif command -v zypper >/dev/null 2>&1; then 35 | zypper install -y dkms git kernel-default-devel 36 | elif command -v dnf >/dev/null 2>&1; then 37 | dnf install -y dkms git kernel-devel 38 | elif command -v yum >/dev/null 2>&1; then 39 | yum install -y dkms git kernel-devel 40 | fi 41 | 42 | tmp=$(mktemp -d aind-kmod-install.XXXXXXXXXX --tmpdir) 43 | git clone https://github.com/anbox/anbox-modules $tmp/anbox-modules 44 | ( 45 | cd $tmp/anbox-modules 46 | cp -f anbox.conf /etc/modules-load.d/ 47 | cp -f 99-anbox.rules /lib/udev/rules.d/ 48 | cp -rTf ashmem /usr/src/anbox-ashmem-1 49 | cp -rTf binder /usr/src/anbox-binder-1 50 | dkms install anbox-ashmem/1 51 | dkms install anbox-binder/1 52 | modprobe ashmem_linux 53 | modprobe binder_linux 54 | ) 55 | rm -rf $tmp 56 | -------------------------------------------------------------------------------- /hack/translate-dockerfile-runopt-directive.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # From https://raw.githubusercontent.com/rootless-containers/usernetes/v20200309.0/hack/translate-dockerfile-runopt-directive.sh 3 | 4 | # Input: 5 | # FROM ... 6 | # ... 7 | # # runopt = --mount=type=cache,target=/root/.cache 8 | # RUN foo 9 | 10 | # Output: 11 | # # syntax = docker/dockerfile:1-experimental 12 | # FROM ... 13 | # ... 14 | # RUN --mount=type=cache,target=/root/.cache foo 15 | 16 | echo '# syntax = docker/dockerfile:1-experimental' 17 | 18 | last_runopt="" 19 | while IFS="" read -r line || [[ -n $line ]]; do 20 | run=$(echo $line | grep -ioP '^\s*RUN\s+\K.+') 21 | printed="" 22 | if [[ -n $run && -n $last_runopt ]]; then 23 | echo "RUN $last_runopt $run" 24 | printed=1 25 | fi 26 | last_runopt=$(echo $line | grep -ioP '^#\s*runopt\s*=\s*\K.+') 27 | if [[ -z $last_runopt && -z $printed ]]; then 28 | echo "$line" 29 | fi 30 | done 31 | -------------------------------------------------------------------------------- /kube/aind.yaml: -------------------------------------------------------------------------------- 1 | # aind manifest for Kubernetes 2 | # 3 | # See README.md for the clusters known to work with. 4 | # 5 | # NOTE: replace "ghcr.io/aind-containers/aind:latest" with "ghcr.io/aind-containers/aind@sha256:" for reproducible deployment. 6 | --- 7 | apiVersion: apps/v1 8 | kind: Deployment 9 | metadata: 10 | labels: 11 | app: aind 12 | name: aind 13 | spec: 14 | replicas: 1 15 | selector: 16 | matchLabels: 17 | app: aind 18 | template: 19 | metadata: 20 | labels: 21 | app: aind 22 | spec: 23 | initContainers: 24 | - name: install-kmod 25 | image: ghcr.io/aind-containers/aind:latest 26 | command: ["/bin/bash"] 27 | args: ["-exc", "cp -f /install-kmod.sh /host/tmp/aind-install-kmod.sh && cd /host && chroot . bash /tmp/aind-install-kmod.sh"] 28 | securityContext: 29 | privileged: true 30 | volumeMounts: 31 | - name: host-root 32 | mountPath: /host 33 | # Remounting /sys as read-write in initContainers propagates to the Pod sandbox and the containers. 34 | # Required by anbox session-manager. 35 | # https://github.com/aind-containers/aind/issues/21 https://github.com/containerd/containerd/issues/3221 https://github.com/moby/moby/issues/24000#issuecomment-613194003 36 | - name: fix-sandbox-sysfs 37 | image: ghcr.io/aind-containers/aind:latest 38 | command: ["/bin/bash"] 39 | args: ["-exc", "mount -o remount,rw /sys"] 40 | securityContext: 41 | privileged: true 42 | containers: 43 | - name: aind 44 | image: ghcr.io/aind-containers/aind:latest 45 | tty: true 46 | securityContext: 47 | privileged: true 48 | ports: 49 | - containerPort: 5900 50 | volumeMounts: 51 | - name: host-lib-modules 52 | readOnly: true 53 | mountPath: /lib/modules 54 | resources: 55 | requests: 56 | memory: 2048m 57 | cpu: 500m 58 | livenessProbe: 59 | exec: 60 | command: ["pgrep", "-f", "org.anbox.appmgr"] 61 | initialDelaySeconds: 20 62 | periodSeconds: 15 63 | volumes: 64 | - name: host-root 65 | hostPath: 66 | path: / 67 | - name: host-lib-modules 68 | hostPath: 69 | path: /lib/modules 70 | # NOTE: Set the following nodeSelector if you have non-Ubuntu (i.e. cos) node pools on GKE 71 | # nodeSelector: 72 | # cloud.google.com/gke-os-distribution: ubuntu 73 | --- 74 | apiVersion: v1 75 | kind: Service 76 | metadata: 77 | labels: 78 | app: aind 79 | name: aind 80 | spec: 81 | ports: 82 | - port: 5900 83 | protocol: TCP 84 | selector: 85 | app: aind 86 | -------------------------------------------------------------------------------- /src/anbox-container-manager-pre.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eux -o pipefail 3 | if [ $(id -u) != 0 ]; then 4 | echo >&2 "must be executed as root" 5 | exit 1 6 | fi 7 | 8 | # ashmem 9 | grep -q ashmem /proc/misc || 10 | /sbin/modprobe ashmem_linux 11 | if [ ! -e /dev/ashmem ]; then 12 | mknod /dev/ashmem c 10 55 13 | fi 14 | 15 | # binder (newer kernel uses /dev/binderfs directory; older kernel uses /dev/binder file) 16 | grep -q binder /proc/devices || grep -q binder /proc/misc || 17 | /sbin/modprobe binder_linux 18 | if grep binder /proc/filesystems; then 19 | if [ ! -e /dev/binderfs/binder-control ]; then 20 | mkdir -p /dev/binderfs 21 | mount -t binder none /dev/binderfs 22 | fi 23 | else 24 | if [ ! -e /dev/binder ]; then 25 | mknod /dev/binder c 511 0 26 | fi 27 | fi 28 | -------------------------------------------------------------------------------- /src/anbox-container-manager.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Anbox Container Manager 3 | After=network.target 4 | Wants=network.target 5 | 6 | [Service] 7 | ExecStartPre=/usr/local/bin/anbox-container-manager-pre.sh 8 | ExecStartPre=/usr/local/share/anbox/anbox-bridge.sh start 9 | ExecStart=/usr/local/bin/anbox container-manager --daemon --data-path=/var/lib/anbox --android-image=/aind-android.img --use-rootfs-overlay --force-squashfuse 10 | ExecStopPost=/usr/local/share/anbox/anbox-bridge.sh stop 11 | 12 | [Install] 13 | WantedBy=docker-entrypoint.target 14 | -------------------------------------------------------------------------------- /src/docker-2ndboot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # docker-2ndboot.sh is executed as a non-root user via `unsudo`. 3 | 4 | if [ -z "${INHERIT_DISPLAY:-}" ]; then 5 | INHERIT_DISPLAY=0 6 | [ -n "${DISPLAY:-}" ] && INHERIT_DISPLAY=1 7 | fi 8 | 9 | function finish { 10 | set +x 11 | figlet ERROR 12 | : FIXME: the container should shutdown automatically here 13 | } 14 | trap finish EXIT 15 | 16 | function waitUntil() { 17 | local message=$1 18 | local count=$2 19 | until $3; do 20 | echo "$message" 21 | count=$((count - 1)) 22 | [ $count -lt 1 ] && return 1 23 | sleep 1 24 | done 25 | return 0 26 | } 27 | 28 | cd $(realpath $(dirname $0)/..) 29 | set -eux 30 | 31 | export EGL_PLATFORM=x11 32 | 33 | if [ $INHERIT_DISPLAY -eq 0 ]; then 34 | mkdir -p ~/.vnc 35 | if [ ! -e ~/.vnc/passwdfile ]; then 36 | set +x 37 | echo $(head /dev/urandom | tr -dc a-z0-9 | head -c 32) > ~/.vnc/passwdfile 38 | set -x 39 | fi 40 | 41 | Xvfb & 42 | export DISPLAY=:0 43 | 44 | if ! waitUntil "Waiting for ready X11 server" 10 "[ -e /tmp/.X11-unix/X0 ]"; then 45 | exit 1 46 | fi 47 | sleep 1 48 | x11vnc -usepw -ncache 10 -forever -bg 49 | 50 | fvwm & 51 | fi 52 | 53 | if [ $WEBMODE = "1" ]; then 54 | echo "running websockify..." 55 | websockify -D --web /usr/share/novnc/ 0.0.0.0:8080 127.0.0.1:5900 56 | echo "websockify -> $?" 57 | fi 58 | 59 | if ! systemctl is-system-running --wait; then 60 | systemctl status --no-pager -l anbox-container-manager 61 | journalctl -u anbox-container-manager --no-pager -l 62 | exit 1 63 | fi 64 | systemctl status --no-pager -l anbox-container-manager 65 | 66 | if ! waitUntil "Waiting for ready /run/anbox-container.socket" 10 "[ -e /run/anbox-container.socket ]"; then 67 | exit 1 68 | fi 69 | 70 | anbox session-manager ${SESSION_MANAGER_ARGS:-} & 71 | if ! waitUntil "Waiting for ready anbox" 60 "anbox wait-ready"; then 72 | exit 1 73 | fi 74 | anbox launch --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity 75 | 76 | adb wait-for-device 77 | 78 | # install apk (pre-installed apps such as F-Droid) 79 | for f in /apk-pre.d/*.apk; do adb install -r $f; done 80 | 81 | # install apk 82 | if ls /apk.d/*.apk; then 83 | for f in /apk.d/*.apk; do adb install -r $f; done 84 | fi 85 | 86 | [ -n "${POST_SESSION_SCRIPT:-}" ] && . $POST_SESSION_SCRIPT 87 | 88 | 89 | # done 90 | figlet "Ready" 91 | echo "Hint: the password is stored in $HOME/.vnc/passwdfile" 92 | exec sleep infinity 93 | -------------------------------------------------------------------------------- /src/patches/anbox/README.md: -------------------------------------------------------------------------------- 1 | The Anbox patches in this directory (if any) are licensed under the terms of [the GNU General Public License, Version 3](https://github.com/anbox/anbox/blob/master/COPYING.GPL), corresponding to [Anbox](https://github.com/anbox/anbox) itself. 2 | -------------------------------------------------------------------------------- /src/unsudo: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eux 3 | car=$1 4 | shift 5 | cdr=$@ 6 | 7 | if [ -d /home/user/.vnc ]; then 8 | chown user:user /home/user/.vnc 9 | fi 10 | 11 | # machinectl requires absolute path 12 | params=("shell") 13 | avail_envs="INHERIT_DISPLAY DISPLAY SESSION_MANAGER_ARGS POST_SESSION_SCRIPT WEBMODE" 14 | for name in $avail_envs; do 15 | [ -n "${!name:-}" ] && params+=("--setenv=$name=${!name}") 16 | done 17 | params+=("user@" "$(which $car)" "$@") 18 | exec machinectl "${params[@]}" 19 | 20 | --------------------------------------------------------------------------------