Skip to content

mosquitto Eclipse Mosquitto

Eclipse Mosquitto is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol.

I use it to extract devices from rtl_433.

⚙ Config

Web port: 9001

Interface port: 1883

User: mosquitto

UID: 1883

Group: mosquitto

GID: 1883

compose.yaml
  mosquitto:
    image: eclipse-mosquitto:2.0.22
    container_name: mosquitto
    volumes:
      - ./mosquitto:/mosquitto
      - ./mosquitto/data:/mosquitto/data
      - ./mosquitto/log:/mosquitto/log
      - ./mosquitto/config:/mosquitto/config
      - /etc/localtime:/etc/localtime:ro
      - ./mosquitto/config/password.txt:/mosquitto/config/password.txt
    ports:
      - 1883:1883
      - 9001:9001
    restart: unless-stopped
    networks:
      - localnet

🔐 Permissions

By default, the eclipse-mosquitto Docker image is run using the mosquitto:mosquitto 1883:1883 user and group.

To be able to edit the config file using the current user on the host, the mosquitto group needs to be added to the host system and the host user needs to be added to the group.

Add the mosquitto group

Host
sudo groupadd -g 1883 mosquitto

Add current user to the mosquitto group

Host
sudo usermod -aG mosquitto $(whoami)

Check

Host
cat /etc/group | grep 1883
Output
mosquitto:x:1883:username

📁 Setup Directories

Make directories

Host
mkdir -p ./mosquitto/config ./mosquitto/data ./mosquitto/log

Grant group write

Host
sudo chmod -R g+w ./mosquitto

Change folder permissions

Host
sudo chown -R 1883:1883 ./mosquitto

🔒 Credentials

Generate username and password for mosquitto.

./mosquitto/config/password.txt

Host
sudo touch ./mosquitto/config/password.txt
docker compose up mosquitto -d
Host
docker exec -it mosquitto mosquitto_passwd -c /mosquitto/config/password.txt username
Host
docker exec -it mosquitto sh
Docker container
mosquitto_passwd -c /mosquitto/config/password.txt username
chown root:root /mosquitto/config/password.txt
exit 

Change permissions again

Host
sudo chown -R 1883:1883 ./mosquitto

Check

sudo cat ./mosquitto/config/password.txt
docker exec -it mosquitto cat /mosquitto/config/password.txt
Output
username:$7$101$o0s01iFdr/lPCuvc$HEUdUhd50k212ZV/B9bjLYb/iKC6R+4srHgVz+3LbIebVavtD+5uRumiEOZGZOdy5LNq/siDdlxXxomOM8u3jA==

Stop the container

Host
docker compose down mosquitto

Check that it's not running

Host
docker container ps
Output
CONTAINER ID    IMAGE    COMMAND    CREATED   STATUS  PORTS   NAMES

ha Home Assistant

Note

The Broker should match the container name of Eclipse Mosquitto and the username and password should match the generated ones above.

Broker: mosquitto

Port: 1883

Username: username

Password: password

🔗 References