Skip to content

BYOC: Docker / Docker Compose ​

The simplest BYOC setup: one Linux VM in your cloud account with Docker. Read the BYOC overview first for the Broker ID, ports and requirements.

docker run ​

bash
docker run -d --name connectmq-broker --restart unless-stopped \
  -p 1883:1883 -p 8883:8883 -p 8083:8083 -p 8084:8084 \
  -e BROKER_ID=my-broker-01 \
  -e BROKER_SECRET_KEY='<your-secret>' \
  -e PUBLIC_BROKER_ENABLED=false \
  -v connectmq-logs:/app/logs \
  -v /etc/connectmq/certs:/app/certs:ro \
  connectmqcom/broker:1.0.0

Order matters

Write every option (-e, -p, -v) before the image name. Anything after the image name is passed to the broker as an argument, not as an environment variable. The container exits with code 1 if the secret is missing, the Central API is unreachable or the credentials are rejected: check docker logs connectmq-broker first.

Docker Compose ​

yaml
services:
  connectmq-broker:
    image: connectmqcom/broker:1.0.0
    restart: unless-stopped
    environment:
      BROKER_ID: my-broker-01
      BROKER_SECRET_KEY: ${BROKER_SECRET_KEY}   # from .env, never commit it
      PUBLIC_BROKER_ENABLED: "false"
    ports: ["1883:1883", "8883:8883", "8083:8083", "8084:8084"]
    volumes:
      - connectmq-logs:/app/logs
      - ./certs:/app/certs:ro
volumes:
  connectmq-logs:

Put BROKER_SECRET_KEY=... in a .env file next to docker-compose.yml (and in .gitignore), then run docker compose up -d. The repository contains this file, an .env.example and a default config/broker.json.

TLS with Let's Encrypt ​

Combine the certificate chain and the private key into one PEM file that the container user (UID 1654) can read:

bash
cat /etc/letsencrypt/live/mqtt.example.com/fullchain.pem \
    /etc/letsencrypt/live/mqtt.example.com/privkey.pem > /etc/connectmq/certs/broker.pem
chown 1654:1654 /etc/connectmq/certs/broker.pem && chmod 400 /etc/connectmq/certs/broker.pem
docker restart connectmq-broker   # after each renewal

Clients then connect to mqtts://mqtt.example.com:8883 or wss://mqtt.example.com:8084/mqtt with their ConnectMQ credentials.

Firewall ​

  • Inbound: 8883 and 8084 from your devices (1883 and 8083 only from private networks).
  • Outbound: 443 to brokerapi.connectmq.com.

Next: Verify, update & troubleshoot.

Fully managed MQTT broker for connected devices.