MirrorNest
← Todos os guias

Mosquitto MQTT broker

A free, open-source, lightweight MQTT message broker -- the standard messaging backbone connecting smart-home sensors/devices to automation platforms like Home Assistant and Node-RED.

Destino: Any Docker hostHome AutomationIoTNetworkingSite oficial ↗Documentação oficial ↗
Este guia foi elaborado a partir da documentação oficial do Mosquitto MQTT broker, ligada acima — verifique sempre lá os nomes exatos dos pacotes/versões antes de executar estes comandos num servidor de produção, uma vez que as versões da distribuição e do projeto mudam com o tempo.
  1. 1Create a minimal config file

    Mosquitto's Docker image refuses external connections with no config by default -- this enables a plain listener for local network use.

    mkdir -p mosquitto/config
    cat > mosquitto/config/mosquitto.conf <<'EOF' listener 1883 allow_anonymous true EOF

    allow_anonymous true means no username/password is required -- fine for a trusted home LAN, not for anything reachable from the internet. See Mosquitto's docs for password-file-based auth before exposing it externally.

  2. 2Run the container

    docker run -d \ --name mosquitto \ --restart unless-stopped \ -p 1883:1883 \ -v "$(pwd)/mosquitto/config:/mosquitto/config" \ eclipse-mosquitto
  3. 3Test it with the mosquitto client tools

    The subscriber should print "hello" -- confirms the broker is relaying messages correctly.

    mosquitto_sub -h <the-server's-ip> -t test/topic &
    mosquitto_pub -h <the-server's-ip> -t test/topic -m "hello"