Standalone Mosquitto MQTT-Broker mit docker-compose einrichten

English Deutsch

docker-compose.yml

docker-compose.yml
services:
  mosquitto:
    image: eclipse-mosquitto
    network_mode: host
    volumes:
      - ./config:/mosquitto/config
      - ./data:/mosquitto/data
      - ./log:/mosquitto/log

Erstellen Sie nun config/mosquitto.conf

mosquitto.conf
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log

listener 1883
## Authentifizierung ##
# allow_anonymous false
password_file /mosquitto/config/mosquitto.passwd

Erstellen Sie nun den ersten Benutzer mit

docker-compose run mosquitto mosquitto_passwd -c /mosquitto/config/mosquitto.passwd mosquitto

create_mosquitto_user.sh
docker-compose run mosquitto mosquitto_passwd -c /mosquitto/config/mosquitto.passwd mosquitto

Sie können optional weitere Benutzer mit dem -b-Flag (Batch) anstelle von -c erstellen und das Passwort auf der Kommandozeile angeben:

docker-compose run mosquitto mosquitto_passwd -b /mosquitto/config/mosquitto.passwd seconduser shoaCh3ohnokeathal6eeH2marei2o

add_mosquitto_user.sh
docker-compose run mosquitto mosquitto_passwd -b /mosquitto/config/mosquitto.passwd seconduser shoaCh3ohnokeathal6eeH2marei2o

Starten Sie nun Mosquitto mit

docker-compose up

docker_compose_up.sh
docker-compose up

oder erstellen Sie einen systemd-Service für den automatischen Start.

Wir betreiben Mosquitto mit network_mode: host. Mosquitto wird standardmäßig auf Port 1883 (MQTT) lauschen. Sie können weitere Dienste über config/mosquitto.conf konfigurieren, siehe diesen StackOverflow-Beitrag für weitere Informationen.


Check out similar posts by category: MQTT