Skip to content

Commit

Permalink
♻️ refact(docker): Remove docker compose version (#7)
Browse files Browse the repository at this point in the history
Also:
- refact volumes part to have dedicated folders with valid rights
- update documentation
  • Loading branch information
vvatelot authored Oct 13, 2022
1 parent 4ea8c45 commit c9a598c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
data/mosquitto.db
log/mosquitto.log
config/mosquitto.conf
config/password.txt
40 changes: 25 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
9 changes: 6 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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: ~
Empty file added log/.gitkeep
Empty file.

0 comments on commit c9a598c

Please sign in to comment.