This application sets up a Mosquitto MQTT broker using Docker. Mosquitto is an open-source message broker that implements the MQTT protocol. It's designed for lightweight and efficient messaging, making it ideal for IoT and device communication. This setup includes Docker configurations and scripts to manage the Mosquitto service.
.
├── .env
├── .gitignore
├── docker-compose.yaml
├── LICENSE
├── README.md
└── mosquitto/
├── entrypoint.sh
└── config/
└── mosquitto.conf
.env
: Environment variables file..gitignore
: Specifies intentionally untracked files to ignore.docker-compose.yaml
: Docker Compose configuration file.LICENSE
: The license file for the project.README.md
: This file, providing documentation.mosquitto/
: Directory containing Mosquitto broker configurations.entrypoint.sh
: Entrypoint script for the Docker container.config/
: Contains Mosquitto configuration files.mosquitto.conf
: Mosquitto broker configuration file.
- Docker and Docker Compose installed.
- Basic knowledge of MQTT protocol and Docker usage.
- Clone the repository to your local machine.
- Navigate to the root directory of the project.
- Configure the
.env
file with necessary environment variables. - Run
docker-compose up
to start the Mosquitto MQTT broker.
- Mosquitto Configuration (
mosquitto.conf
): Configures the MQTT broker, including persistence settings, logging, listeners for MQTT and WebSockets, and bridge configuration. - Entrypoint Script (
entrypoint.sh
): Manages the creation and updating ofpasswords.txt
for MQTT authentication, modifiesmosquitto.conf
based on environment variables, and starts the Mosquitto broker.
MQTT_USERNAME
andMQTT_PASSWORD
: Credentials for MQTT users.REMOTE_SERVER
,REMOTE_PORT
,REMOTE_USERNAME
,REMOTE_PASSWORD
, andDEVICE_ID
: Used for configuring MQTT bridge to a remote broker.
Example .env file (CHANGE USERNAME & PASSWORDS!)
# device name for
DEVICE_ID=this_device
MQTT_USERNAME=this_mqtt_user
MQTT_PASSWORD=this_mqtt_pass
# Bridge Configuration - This section will be modified or removed based on environment variables in entrypoint script
# The bridge configuration allows Mosquitto to connect to a remote MQTT broker and forward messages between the two brokers.
# Set the REMOTE_SERVER variable below to connect this as a node.
# REMOTE_SERVER=your_mqtt_server
# REMOTE_USERNAME=your_mqtt_username
# REMOTE_PASSWORD=your_mqtt_password
# REMOTE_PORT=your_mqtt_port
- After running
docker-compose up
, the Mosquitto broker will be available on the specified ports for MQTT and WebSocket connections. - Clients can connect to the broker using the MQTT protocol or WebSockets.
- The broker can also connect to a remote MQTT broker as a bridge if configured.
This project is licensed under [LICENSE]. Please refer to the license file for details.
Contributions to this project are welcome. Please follow standard GitHub pull request procedures.
For support and queries, please open an issue in the GitHub repository.
Note: This README assumes a certain level of familiarity with MQTT, Docker, and Docker Compose. Users are expected to have basic knowledge of these technologies to effectively use this application.