Back to MQTT
Setting up MQTT
Setting up Mosquitto, the broker almost everyone means when they say "MQTT server."
- 1
Write a minimal config
Mosquitto refuses anonymous connections and listens on nothing by default; a couple of lines fix both for a local setup.
# mosquitto.conf listener 1883 allow_anonymous false password_file /mosquitto/config/passwd - 2
Run the container
Mount the config alongside a data and log directory.
services: mosquitto: image: eclipse-mosquitto:latest container_name: mosquitto restart: unless-stopped ports: - "1883:1883" volumes: - ./config:/mosquitto/config - ./data:/mosquitto/data - ./log:/mosquitto/log - 3
Create a user
Run this once to create the password file referenced above; add -c only the first time, since it overwrites the file.
docker exec -it mosquitto mosquitto_passwd -c /mosquitto/config/passwd homeassistant - 4
Point other services at it
Anything that speaks MQTT (Home Assistant, Frigate, custom scripts) connects using this container's address, port 1883, and the username and password just created.
Further reading
- Mosquitto documentation
Full configuration reference, including TLS and websocket listeners not covered here.
- Eclipse Mosquitto on GitHub
Source for the broker this image is built from.