Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to add support for running containers under Android (GOOS=android) #41111

Open
FreddieOliveira opened this issue Jun 16, 2020 · 38 comments
Labels
area/distribution kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.

Comments

@FreddieOliveira
Copy link
Contributor

Sorry to open an issue similar to dozens of others, but this one is not a duplicatedof any of those (yes, I check all of them to say that. In fact, I checked every single post throughout the whole internet about running docker in Android (or at least I think so)). Here's some considerations regarding this issue:

  1. I do understand the requirements to run docker on a device;
  2. I do have a custom kernel that supports running docker. I'm even able to run docker containers inside a chrooted environment within an GNU/Linux rootfs. That proves my kernel fully supports docker;
  3. I'm also already able to run docker directly in Android (no chroot and no VM emulation with qemu or whatever)

Even though I'm already able to run dockerd, containerd, runc, dockercli, tini and all other requirements, and here's the prove:

(this is docker running in my Redmi Note 7 in termux terminal emulator)

it doesn't serve of anything, since there's no container that supports the Android OS. This becomes clear when you try to docker run pretty much any container and all you get is no matching manifest for android/arm64 in the manifest list entries error:

Screenshot_20200531-203509_Termux

Despite aarch64 is supported by the majority of containers, the Android OS is not. So, If you then try to run a Linux version of that container with the flag --platform=linux/arm64 you'll get the operating system is not supported error:

Screenshot_20200531-211606_Termux

If you then patch docker source code to ignore this error and continue anyway (because like me, you don't agree that Android can't run Linux container), you'll finally get a segmentation fault:

Screenshot_20200531-211226_Termux

So, my issue is, more specifically, about the containers starting to support Android or, more feasibly, docker starting to make Android support Linux containers.

@AkihiroSuda AkihiroSuda changed the title Possibility to add support for running containers under Android Possibility to add support for running containers under Android (GOOS=android) Jun 16, 2020
@AkihiroSuda AkihiroSuda added kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. area/distribution labels Jun 16, 2020
@FreddieOliveira
Copy link
Contributor Author

OK, an update on this. I've just successfully made it happen:

2020_06_17_125704

As I said, I don't agree that Android can't run Linux containers, so what I did was to replace every occurrence of runtime.GOOS by "linux", thus spoofing my Android OS as a Linux. And it worked! Simple like that.

I don't know how complex it would be to support Android OS the proper way, but this workaround proves that Android can indeed run Linux container, and more over, proves that docker works fine in Android.

It would be amazing if you guys add an official support for this.

@cpuguy83
Copy link
Member

Probably there could be a config for supported platforms, maybe some auto-detection like buildx does.

/cc @tonistiigi

@hnmn
Copy link

hnmn commented Oct 1, 2020

any updates ? @cpuguy83

@chrisbward
Copy link

Absolutely needs to happen!

@mmBesar
Copy link

mmBesar commented Nov 2, 2020

Docker on android would be great

@FreddieOliveira
Copy link
Contributor Author

FreddieOliveira commented Jan 11, 2021

I've just finished writing a step by step guide on how to get docker working on Android in this gist.

After 7 months using it I can say that docker works pretty stable on Android. Again, with no VMs nor chroot. Docker runs pretty stable directly and purely on Android. The only thing I couldn't manage to work is the network isolation for the containers. For now, the only way to give internet access to containers is using the --net=host flag. The tun tap interface is successfully created, but the containers won't have internet access. Probably it's a silly issue I haven't figured out yet. But, besides that, everything works fine. I'm even able to run GUI programs inside the container and interact with them using the VNC Viewer Android app.

Edit: @yjwong figured out how to make the bridge network driver work

I'd like to hear from the Dev team @AkihiroSuda @cpuguy83 @thaJeztah @tonistiigi. Hear anything actually. Because after all this time this is still an issue in Limbo without any comments.

I know that Docker is an important project, used by others very important projects and companies. Its stability is crucial and starting supporting a new operating system is an extremely delicated process. The changes introduced in the source code may crash other things not related with this that were perfectly working before. I understand that, because I'm also a dev. Besides, only few people around the world would be able to run it on their phones because of how much kernel modification it requires. But even a no, it's impossible to run docker on Android, you're the only guy on earth that managed it and it's not worth our time is appreciated than no answer whatsoever.

@mad-ady
Copy link

mad-ady commented Feb 1, 2021

I'd like to add to @FreddieOliveira comment that Docker for Android wouldn't run only on resource-limited phones. It could run on boards like Odroid N2+ where the OS would be Android - for the apps/user experience, but since the board is powerful and can run always-on, it could also run some docker containers to handle all sorts of non-android "server" apps (e.g. run Home Assistant).

@PatrykCzarnota
Copy link

I've tested @FreddieOliveira guide also whether it works without termux. I've compiled it with little changes and generate Android system image with included binaries at /system/bin/ directory. It works perfect without any problems so far. No need termux app. Pretty solution when you've got Android source codes (AOSP) for your phone or dev board.

@FreddieOliveira
Copy link
Contributor Author

FreddieOliveira commented Feb 19, 2021

Docker was added to Termux repo, that means it's not necessary to compile it manually anymore. You can install it by simply executing inside Termux:

pkg install root-repo
pkg install docker

And that's it!

Note, however, that you still need a rooted phone with a modified kernel to successfully run docker on Android.

@alexanderadam
Copy link

alexanderadam commented Feb 19, 2021

@FreddieOliveira can't this ticket be closed then? 🤔

Nevermind, see below.

@PatrykCzarnota
Copy link

@alexanderadam I hope not. There would be nice to compile docker with official support for Android without @FreddieOliveira patches.

@alexanderadam
Copy link

Ah sorry, I misread this topic!

@techieshark
Copy link

I was thinking of experimenting with a little web server using Docker on a phone. So, +1 for this.

@alansikora

This comment has been minimized.

@s20208413
Copy link

If running containers on Android is possible, a very cheap old (not too old) phone can be a small server.

It's very useful !

@lizelive
Copy link

this is good and important

@haochunchang
Copy link

+1 for this.

@ch1p2
Copy link

ch1p2 commented May 21, 2022

please add support for android. (not too) old smartphones are definitely more economical than raspberry pi. (and some of the cheap old phones even have better hardware than raspberry pi)

@ty11111111
Copy link

Support for Android would be amazing

@Eliab-LB
Copy link

This could be amazing for reusing cell phones, I think we all have an Android lying around unused.
Also, in my case to help our communities with no internet access to teachers in schools, this will be very useful.

@psingh-zenon
Copy link

Old android phones have more powerful hardware than something like raspberry pi, with built in UPS (the battery). Is much more efficient as well. Docker team should consider official support, open source community can take it forward after that.

@sauravmahuri2007
Copy link

I reached to this post because I wanted my old phone act like a server. I wish the same, docker should be installed natively to Android.

@MRColorR
Copy link

MRColorR commented Nov 2, 2022

Given the hardware capabilities of today's smartphones it would be fantastic to be able to use docker on android without too much difficulty. it would open up a new world

@rubel-sh

This comment was marked as spam.

@lecomelli

This comment was marked as spam.

@martintimmer
Copy link

+1 here as well
@FreddieOliveira don’t give up your hopes on this! Thank you for all your dedication to this project!

@yibo-liang
Copy link

+1 For any possibility.

@elvisisvan
Copy link

here from this gist: https://gist.github.com/FreddieOliveira/efe850df7ff3951cb62d74bd770dce27

which was led to from this reddit reply: https://www.reddit.com/r/termux/s/KiPKxsz55n

Upvote for this🔺

@adriancuadrado
Copy link

I've just finished writing a step by step guide on how to get docker working on Android in this gist.

After 7 months using it I can say that docker works pretty stable on Android. Again, with no VMs nor chroot. Docker runs pretty stable directly and purely on Android. The only thing I couldn't manage to work is the network isolation for the containers. For now, the only way to give internet access to containers is using the --net=host flag. The tun tap interface is successfully created, but the containers won't have internet access. Probably it's a silly issue I haven't figured out yet. But, besides that, everything works fine. I'm even able to run GUI programs inside the container and interact with them using the VNC Viewer Android app.

Edit: @yjwong figured out how to make the bridge network driver work

I'd like to hear from the Dev team @AkihiroSuda @cpuguy83 @thaJeztah @tonistiigi. Hear anything actually. Because after all this time this is still an issue in Limbo without any comments.

I know that Docker is an important project, used by others very important projects and companies. Its stability is crucial and starting supporting a new operating system is an extremely delicated process. The changes introduced in the source code may crash other things not related with this that were perfectly working before. I understand that, because I'm also a dev. Besides, only few people around the world would be able to run it on their phones because of how much kernel modification it requires. But even a no, it's impossible to run docker on Android, you're the only guy on earth that managed it and it's not worth our time is appreciated than no answer whatsoever.

@AkihiroSuda @cpuguy83 @thaJeztah @tonistiigi. Is this going to be planned? Is this at least being discussed? Please give updates, this would be so cool!

@AkihiroSuda
Copy link
Member

@adriancuadrado

@adriancuadrado
Copy link

I just created a feature request asking the Android kernel developers to add support for containers here.

Please everyone consider upvoting it to give it more precedence:

image

@adriancuadrado
Copy link

image

@AkihiroSuda Apparently the Android kernel doesn't have to support containers because it already supports whatever features are needed to implement them, if I understood it correctly.

Disclaimer: I'm kinda lost here because I don't have any experience at all with kernel development.

@adriancuadrado
Copy link

@adriancuadrado

@AkihiroSuda

Regarding the first 2 points, since @FreddieOliveira created the patches, my understanding is that it would be his responsability to edit them to make them mergeable without breaking non-Android Linux due to the hard-coded paths like "/data/data/com.termux/files/home/.docker" (Unless someone else offers as a volunteer to do this, ofc. I wouldn't mind trying but as I said I don't have any experience with kernel development).

For the third point, see my previous comment.

And for the last one, the whole point of using containerization is to avoid the extra resources VMs take. You can run containers in a VM, but they would run much faster without VMs.

@AkihiroSuda
Copy link
Member

@adriancuadrado

Apparently the Android kernel doesn't have to support containers because it already supports whatever features are needed to implement them, if I understood it correctly.

Disagree.
https://android.googlesource.com/kernel/configs/+/refs/heads/main/v/android-6.6/android-base.config (the default config for Android kernel 6.6) doesn't even seem to have essential flags such as CONFIG_PID_NS, CONFIG_CGROUP_DEVICE, etc.

See https://github.com/moby/moby/blob/master/contrib/check-config.sh for the needed configs.

@adriancuadrado
Copy link

adriancuadrado commented Jan 2, 2024

@AkihiroSuda

image

@FreddieOliveira
Copy link
Contributor Author

@AkihiroSuda

I've never submitted any pull request because I didn't know if it was a desired contribution, since no moby member ever commented on this. But now that I finally saw an interaction here from a member, I can review and rewrite the patches, if that's the case.

About running docker inside a Linux VM, I've already tried that and by personal experience I can say that's extremely inefficient to the point it's more like a POC than a real usable thing. Whereas running it directly on Android is as efficient as running it on a computer.

@adriancuadrado

The Android kernel default configuration indeed misses a lot of necessary features and as we saw in the Google response, it will probably remain like that :/

So, even if the pull requests are accepted, running docker on Android will still require a custom kernel. And even if the features were enabled in the kernel, it's still necessary to have a rooted phone.

@tianon
Copy link
Member

tianon commented Apr 10, 2024

I've never submitted any pull request because I didn't know if it was a desired contribution, since no moby member ever commented on this.

Your very first reply was from a Moby member though 👀 🤔

#41111 (comment)

(and labels being added by another member even before that: #41111 (comment))

@duffman128
Copy link

duffman128 commented Jun 24, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/distribution kind/enhancement Enhancements are not bugs or new features but can improve usability or performance.
Projects
None yet
Development

No branches or pull requests