.NET Core and Docker on Raspberry Pi
I recently broke down and bought a Raspberry Pi 3 <sigh>. I tried really hard to stay away, because I really do not need another hobby.
But, things have improved to the point such that you can do things like run .NET Core apps and Docker containers on the things.
Cross-compilers are available for all 3 main platforms available today (macOS, Linux and Windows).
Folks, this is a $35 USD computer! Man, I wish this was available when I was a teenager.
As a teenager I built an Altair with one of my uncles. An expensive and very primitive computer in comparison. A series of toggle switches (one to push the program counter forward while “programming” it) and LEDs were the user interface of that system.
We were thrilled when we were able to get the thing to display various patterns on the LEDs!
But it was no color organ to say the least.
So with that in mind I set out to turn this computer (priced like a drug store calculator) into a server on which I could run Docker container hosted applications using my favorite WebStack.
In order to run the ASP.NET Core component you are going to want to install Ubuntu MATE on your Raspberry Pi 3.
Note that I did not spend the time to try to get this all running on Raspian as the Microsoft instructions specified Ubuntu. See the prerequisites link on that page.
I did my primary development work on a macOS laptop. On that box I have the following:
On the Raspberry Pi 3 as long as you have Ubuntu MATE installed, the images I created will satisify the requirements there with the exception of Docker. See these instructions to get it installed:
To get started clone these projects on your mac:
- animalsapi – sample service application hosting the ASP.NET Core Web API service used by flexlayout
- flexlayout – Angular 4 app that uses animalsapi in its Animals menu item
The steps to build and run these are documented in their associated README.md files. So I will not duplicate that here.
I had a blast putting this together. And I am pleased at the state of things with regards to the Raspberry Pi platform. A lot of people are interested in this as an R&D platform for the Internet of Things (IoT) world that has arrived.
However, there are a few warts that I ran into.
- Docker Hub does not currently support automated builds for the ARM architecture
- Microsoft does not (yet) have an official SDK available for the ARM architecture – but, one is coming. It just may make it into version 2.0.
- The 1GB RAM limitation on the Raspberry Pi 3 means you cannot run many containers on a single node. With both of my containers running I had ~100MB RAM free. But the call to the service is FAST. I was impressed.
These were the main problems I ran into.
Like I said, I did not attempt this on Raspbian (the most popular OS on Raspberry Pi). This was just an experiment.
Next stop, perhaps emit an air horn blast when someone gets too close to my Raspberry Pi – hosted in Docker containers, of course.
A side effect of this project was working through how to support multiple platforms with Docker. Look at the scripts / Dockerfiles that I wrote to see how I accomplished this.
Please do not follow the code in these projects as an example of how to write production quality code! There are many best-practices not being followed: no unit tests, sparse error checking, inadequate logging, no authentication / authorization, etc.
But the point of all of this was:
- It’s the weekend – have fun (I did!)
- Show that .NET Core / Angular applications can be run on the Raspberry Pi platform and perform reasonably well (given the limitations of the machine)
It was a HUGE success. I am glad I did the project and had to share the result.
Now to spend some time in the pool 🙂