An Alpine Linux image running VerneMQ MQTT broker (https://vernemq.com), supporting swarm mode.
name | description | default |
---|---|---|
SELF_IP | The container IP. It will be discovered in swarm mode. | 127.0.0.1 |
SERVICE_NAME | The swarm service name, used to discover other nodes. Cluster mode is disabled if this variable is empty | "" |
DISCOVERY_NAME | The DNS name to resolve to fetch a list of all nodes. Only used in cluster mode. | "tasks.${SERVICE_NAME}" |
MIN_NODES_SIZE | The minimum number of node to wait before starting when running in cluster mode | 3 |
The vmq-admin utility is located in /usr/share/vernemq/bin/vmq-admin, so you can run:
#!/bin/bash
id=$(docker ps | grep "jbonachera/vernemq:" | awk '{ print $1 }')
docker exec -it $id vmq-admin $@
edit the docker-compose.yml to add the environment variable DISCOVERY_NAME="vernemq"
docker-compose up --scale vernemq=3
A cluster of 3 nodes should be started, and MQTT service should be exposed on a random port on localhost.
docker-compose exec vernemq vmq-admin cluster show
mosquitto_sub -h localhost --host 127.0.0.1 --port $(docker-compose port vernemq 1883 | cut -d : -f 2) -d -t devices/+/temperature/degrees
docker swarm init
docker stack deploy -c docker-compose.yml mqtt