QuanticDev

QuanticDev's Engineering and Software Development Resources

Home View on GitHub

Raspberry Pi: A Developer’s Companion - Complete Guide with Docker

Raspberry Pi is a very compact and cheap computer (about $35). In this article, I am going to talk about how a developer uses Raspberry and why it is a good companion for you. I will also enlighten you on how Raspberry plays along with Docker and how and why to use them together. My Raspberry needed a fresh install for ages now, so I will do that with you. I will also set up Docker so I can host all my services on it using pre-existing Docker images for Node.js, Golang, MongoDB, Redis, and more.

Table of contents:

Resources

You can find the video narration of this article on YouTube: https://www.youtube.com/watch?v=idCG0wSi-fk

Video has additional tips for each principle discussed. If you want to read the comments or leave a comment, do so under the YouTube video. If you want to contribute to the article, make a pull request on GitHub.

My JS-API project used as demonstration in the article:

Great uses of Raspberry Pi:

Most popular Docker images that you can use on your Raspberry:

Why Raspberry Pi

Raspberry Pi is a very compact and cheap computer. The new Raspberry Pi 4 with 1GB of RAM costs only $35. I have it on my desk at work, and here it is how it sits.

Raspberry Pi attached to phone

I have all my charging cables attached to the USB ports. I charge my phones, my headphones, my powerbank, and it all works great since I have the Raspberry attached to a 3A charger. More than its physical usefulness, you want it as a computer. It has a powerful CPU and adequate amounts of RAM for many computing tasks. However, it is especially useful for experimenting, learning, and home-server type of workloads. I will talk more about this in a moment.

Raspberry Pi attached to phone

Why Docker

Docker helps you containerize apps. Why do you want containerized apps? Primarily due to ease of use. You can define all their dependencies in a single Dockerfile, they do not pollute your computer with their files, and they work in isolation for security purposes. When you mess up an app container, you can trash it and create a new one in seconds. Since Docker uses OverlayFS, you can even go back in disk history, just like snapshots in a virtual machine.

OverlayFS

For instance, say you want to host your own website on your Raspberry. Say you need Node.js and MongoDB for it. All you have to do is to install Docker on your Raspberry and pull Node and Mongo images. After you set up your containers, you can start hosting your website. It is a very good learning experience for Docker, and it will help you dig deeper into the Linux ecosystem.

For those who are worried, performance is pretty good since Docker is not virtualization, it still uses the kernel primitives directly. As you can see in the charts, both CPU and network overhead of Docker are negligible.

Raspberry Pi attached to phone

Raspberry Pi attached to phone

How Do I Use My Raspberry Pi as a Developer?

My use case for Raspberry Pi is exactly as I describe d up to this point. I host small internal services in Docker containers at home and at work. Most of them are for experimenting and just messing around. Some of them are for small tasks like FTP server for my external drive and periodically recording the home temperature. I also use it as the staging server for most of my web projects. I use a laptop, so it is not always on, but my Raspberry is. Some of the long-running automated tests for those web services require them to be running for 24 hours straight, so I just deploy them to container in Raspberry and run on it.

What Else Can You Do with a Raspberry Pi as a Developer?

Raspberry Pi Setup

Following are the step-by-step instructions for setting up a new Raspberry Pi starting from scratch. If you do not already have them, you can get a Raspberry Pi, a charger, a microSD, and reader, and Raspbian ISO using the links in the resources section.

If you want, you can watch the video version of this article (on top) to watch me do this live.

Docker Setup

Now it is time to setup Docker. You can also watch the video version of the article to see the live demonstration of me doing this on a Raspberry Pi.

Let your Raspberry reboot and reconnect to it using SSH again.

Sample Docker Node.js Application Setup on Raspberry

Now you have your Raspberry and Docker all set up; you can start being productive with it. We will start by creating a Docker container with a sample web app. For this purpose, we will use JS-API, my open-source project, for easily creating JSON API servers with Node.js. The project is hosted on GitHub and NPM, and the links are in the resources section.

See the video if you want to watch me do this exercise for you.

And that is it. You now have a sample Node.js web app running inside a Docker container in your Raspberry. If you want to experiment, you can find more useful Docker images on Docker Hub using the link in the resources section.

I highly recommend getting a Raspberry to any developer just based on the sheer usefulness of it. You pay a tiny fraction of the price of a computer, and even just the learning experience you get out of it is a huge value. One day, we will be able to use ARM as our primary development platform, and on that day Raspberry like tiny computers will be our primary workstations. Until that day, hold on to your Raspberry. And I will see you next time.