IoT Balena && Rpi 3b+

2019-08-05 00:00:00 +0530

Hi Everyone!

I bought a Raspberry Pi 3B+ some time ago to build a Home automation system, But came around Balena ( It provides a infrastruture to develop, deploy and manage connected IoT (Internet of things) devices at scale! It is built for deploying containers, mostly focused on Containerization

Containerization is a lightweight alternative to full machine virtualization that involves encapsulating an application in a container with its own operating environment. This provides many of the benefits of loading an application onto a virtual machine, as the application can be run on any suitable physical machine without any worries about dependencies.

I will go ahead and explain the building blocks of the application.

The NodeJs project that i have used does a simple authentication with login/logout and creates users in a MONGODB database.


  1. A Node.js project which has to be deployed on the BalenaCloud.
  2. The Dockerfile
  3. The docker-compose.yaml

Two containers are created here

  1. NodeJS Container
  2. MongoDB database Container

What happens inside a Dockerfile ?

  1. We explicitly sepcify that we will be using the NODE image from “balenalib/raspberrypi3-node”
  2. In the Dockerfile we define the working directory for our application which will be used to store our NodeJs authentication module.
  3. The script then copies our code to the working directory.
  4. To build the node.js app we run “npm run install” or if you are using yarn “yarn install”
  5. We them export the port 80 for our node.js app, this will be the internal port for the docker used to communicate with other docker images.
  6. The script executes a command CMD [ “npm”, “start” ] to start the server.

Whats inside the docker-compose.yaml ?

  1. We define the version of our compose as 2, you can read more about it here
  2. We then define two services here a) Web - We specify that this app depends on mongodb b) Mongo - We use mongodb image from “nonoroazoro/rpi-mongo” which is a custom built image for the raspberry pi architecture. As soon as we fire the script the mongodb image gets downloaded and starts on the port 27017.

Now this is a very simple example of what we can accomplish with Balena-Cloud for IoT. We do have a lot of ways of deploying apps like this usind different OS’s. We do have Ubuntu CORE! which gives an added advantage and more control in terms of the OS! plus the security for the IoT world.

Balena cloud supports a variety of devices and the link can be found here.

I have hosted the sample app that i created on GitHub.

Balena also provides a list of example here which can be deployed on your IoT devices.


+91 82848 66938


Hyderabad, TS India