ABUC 2026

<aside> ☝🏻

Code is available here: https://www.dropbox.com/scl/fo/ezj3uargzljpwsfs77nb0/AGHVgUlyQX2W0l6_7Dsd3iM?rlkey=bvgq751m96rkab2893w49h7pt&dl=0

</aside>

A containerized MQTT broker

<aside> 🗣️ based on http://www.steves-internet-guide.com/mosquitto-bridge-configuration/

</aside>

An MQTT broker can be executed as a Docker container. This fact provides flexibility when deploying these services, especially in edge devices like Raspberry Pi.

In this demo we will use

Starting an MQTT broker as a container

We will use Compose, a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Using Compose is a two-step process:

  1. Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment. For more information, see the Compose file reference.
  2. Run docker compose up and the Docker compose command starts and runs your entire app.docker-compose has commands for managing the whole lifecycle of your application:

The docker-compose.yml file below indicates how to start up an MQTT broker locally:

services:
  mosquitto:
    image: eclipse-mosquitto:latest
    container_name: mybroker
    ports:
      - "1883:1883"
    volumes:
      - ./mosquitto:/mosquitto
    networks:
      - pubsub-net

networks:
  pubsub-net:
    driver: bridge

in this case we need a ./mosquitto/config/mosquitto.conf file as simple as this:

allow_anonymous true
listener 1883

Executing docker compose up we will get something like:

[+] up 6/6
 ✔ Image eclipse-mosquitto:latest Pulled                                                                                                7.9s
 ✔ Network broker_pubsub-net      Created                                                                                               0.0s
 ✔ Container mybroker             Created                                                                                               0.1s
Attaching to mybroker
mybroker  | 1770731315: Info: running mosquitto as user: mosquitto.
mybroker  | 1770731315: mosquitto version 2.1.2 starting
mybroker  | 1770731315: Config loaded from /mosquitto/config/mosquitto.conf.
mybroker  | 1770731315: Bridge support available.
mybroker  | 1770731315: Persistence support available.
mybroker  | 1770731315: TLS support available.
mybroker  | 1770731315: TLS-PSK support available.
mybroker  | 1770731315: Websockets support available.
mybroker  | 1770731315: Opening ipv4 listen socket on port 1883.
mybroker  | 1770731315: Opening ipv6 listen socket on port 1883.
mybroker  | 1770731315: mosquitto version 2.1.2 running

check with docker ps -a: