Bringing up Node-RED and mosquitto under "docker compose" on a Raspberry Pi

Progress, actually quite a lot of it:

The problem, neatly stated. Docker is good for bringing up single services ("microservices"), but sometimes your application needs more than one thing running for the whole thing to work. Enter "docker compose", formerly "fig", which automates the process of running various Docker commands in the right order with the right arguments all driven from a configuration file. As described by their documentation:

Compose is a tool for defining and running complex applications with Docker. With Compose, you define a multi-container application in a single file, then spin your application up in a single command which does everything that needs to be done to get it running.

The particular task I have in front of me is launching Node-RED and mosquitto (an MQTT broker) together on a Raspberry Pi 2 which is running Hypriot and Docker. Most of the background for why that's a relevant task is at this post on Hypriot, How to use Docker Compose to run complex multi container apps on your Raspberry Pi, which I dutifully and successfully managed to run all of the examples from.

Emboldened by this I tried to get Wordpress running with MySQL but got stuck because of a variety of things (not the least of which was some over-enthusiastic documentation that downplayed the complexity of that task, and the lack of a Pi-specific Wordpress Docker images). But having had the taste of what might be I carried on until I managed to get something to work for what I really wanted: Node-RED running alongside mosquitto so that I could have a local MQTT broker to talk to.

  image: nieleyde/rpi2-nodered
  command: flows.json
    - /home/pi/node-red:/root/.node-red
    - "1880:1880"
    - mosquitto

  image: nieleyde/rpi-mosquitto
    - "1883:1883"

Some subtleties to note:

The nieleyde/rpi2-nodered runs on the Pi 2; there's a corresponding nieleyde/rpi-nodered for the Pi. Both are ARM images. I haven't yet tweaked this to run on x86, but if you do, you'll need to update the "image" stanzas everywhere.

The "command" and "volumes" stanzas in the nodered configuration serve to make Docker mount a subdirectory on the host machine where the flows.json file is stored; this makes changes to the configuration persistent. If you want a read-only configuration, you'll need to change this; I haven't gotten that far yet. It might also make sense to have a data volume container, but again I'm not there yet.

The "mosquitto" configuration is extremely bare bones and runs the default config, which is wide open. I haven't gotten far enough to replace the config file with something better, but that's an obvious next step.

From within Node-RED you refer to this internal MQTT server at hostname "mosquitto", port "1883". If the links stanza was changed to "mqtt" and the mosquitto section was changed to "mqtt" you'd then refer to the MQTT server at hostname "mqtt".

For further reading:

An issue open on Niel Eyde's rpi-nodered Github, documentation for how to extend this image with your own nodes and flows, where I'm working some of this out.

On the Node-RED Github, Support for Docker install for Node-RED, which is epic and helpful in many ways.

The essential Hypriot weblog, specifically the aforementioned Docker Compose examples and the Hypriot Docker Compose Github repository.