From c9a598c7ddf98784b7d63875f8bebe80a7f1f3e1 Mon Sep 17 00:00:00 2001 From: Vincent Vatelot Date: Thu, 13 Oct 2022 16:00:13 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refact(docker):=20Remove?= =?UTF-8?q?=20docker=20compose=20version=20(#7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also: - refact volumes part to have dedicated folders with valid rights - update documentation --- .gitignore | 1 - README.md | 40 +++++++++++++++++++++++++--------------- docker-compose.yaml | 9 ++++++--- log/.gitkeep | 0 4 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 log/.gitkeep diff --git a/.gitignore b/.gitignore index 321bdc6..402323b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -data/mosquitto.db log/mosquitto.log config/mosquitto.conf config/password.txt \ No newline at end of file diff --git a/README.md b/README.md index ec17735..adb2cbb 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,63 @@ +# Simple Mosquitto broker + ![Mosquitto Logo](https://mosquitto.org/images/mosquitto-text-side-28.png 'Mosquitto') -# Simple Mosquitto broker +This is a simple [Mosquitto](https://mosquitto.org) broker to quickly initialize projects requiring an MQTT broker. -This is a simple [Mosquitto](https://mosquitto.org) broker to to quickly initialize projects requiring an MQTT broker. The config file is in the folder `config/mosquitto.conf`. +## Prerequisite -By default we activated the log and data persistance (respectively in `log` and `data` folder). -The authentication can be activated if needed. +- [Docker](https://www.docker.com/) +- [Docker compose](https://docs.docker.com/compose/) +v1.27.0 (better to have v2) -# How to use +## How to use To start the container, just : -``` -docker-compose up -d +```bash +UID=$UID GID=$GID docker-compose up -d ``` The Mosquitto broker is now available on localhost. You can test it easily (require Mosquitto client): | In one shell: -``` +```bash mosquitto_sub -h localhost -t "sensor/temperature" ``` | In a second shell: -``` +```bash mosquitto_pub -h localhost -t sensor/temperature -m 23 ``` -# Enabling authentication +## Configuration + +The config file is in the file [mosquito.conf](./config/mosquitto.conf) + +By default we activated the log and data persistance (logs are in the `log` folder, and data are stored in a docker voume). + +## Authentication + +### Enable authentication In the config file, just uncomment the `Authentication` part and then restart the container. The default user is `admin/password`. **You always have to restart if you want the modification to be taken in account:** -``` +```bash docker-compose restart ``` -## Change user password / create a new user: +### Change user password / create a new user -``` +```bash docker-compose exec mosquitto mosquitto_passwd -b /mosquitto/config/password.txt user password ``` -## Delete user: +### Delete user -``` +```bash docker-compose exec mosquitto mosquitto_passwd -D /mosquitto/config/password.txt user ``` diff --git a/docker-compose.yaml b/docker-compose.yaml index 9bf12dc..57112c8 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,10 +1,13 @@ -version: "3" - services: mosquitto: image: eclipse-mosquitto:2 volumes: - - ./:/mosquitto/:rw + - ./config/:/mosquitto/config/:ro + - ./log/:/mosquito/log/ + - data:/mosquito/data/ ports: - 1883:1883 - 9001:9001 + +volumes: + data: ~ diff --git a/log/.gitkeep b/log/.gitkeep new file mode 100644 index 0000000..e69de29