https://docs.docker.com/engine/install/
https://docs.docker.com/compose/install/
sudo apt install opensslgit clone https://github.com/gq97a6/mosquitto_server_docker .
rm ./configs/enabled/remove.me ./certs/trusted/remove.me ./certs/self/remove.me ./certs/client/remove.me ./scripts/outputs/remove.me-
certs
- client - Contains client CA certificates
- self - Contains self-signed certificates
- trusted - Contains trusted certificates
-
configs
- enabled - Stores currently used configuration
- disabled - Stores disabled configuration
-
scripts
- outputs - Output directory for scripts below
- copy_cert.sh - Copies Let's Encrypt trusted certificate to ./certs/trusted
- gen_cert.sh - Generates self-signed server certificate (openssl required)
- gen_client_ca.sh - Generates client authority certificates
- gen_new_client.sh - Generates new client certificate
- server.conf - Configuration for generating self-signed server certificate
-
mosquitto.conf - Main mosquitto configuration file
-
passwordfile - Stores credentials for login/password authentication method
A) If you have own trusted certificate from Let's Encrypt:
letsencrypt_dir="/etc/letsencrypt/live/domain.com"bash copy_cert.shB) If you with to generate self-signed certificate:
days = 365
commonName = mqtt.domain.com
DNS.0 = mqtt.domain.combash gen_cert.shImportant
Each generated client certificate is considered valid as long as same client CA certificates are used in server configuration
bash gen_client_ca.shbash gen_new_client.shThis are example configuration files stored in ./configs/disabled
- tcp.conf - Most basic configuration with MQTT over TCP
- ssl.conf - Configuration with MQTT over TLS
- ssl_self.conf - Configuration with MQTT over TLS using self-signed certificates
- ssl_self_cert_auth.conf - Same as above but includes client authentication using certificates
- ws.conf - Configuration with MQTT over WebSockets
- wss.conf - Configuration with MQTT over secure WebSockets
Each listener is also secured by default with basic login/password authentication method
To change this remove this line below in ./mosquitto.conf
password_file /mosquitto/config/passwordfileTip
To create new passwordfile use:
mosquitto_passwd -c passwordfile user
To create add new user to password file use:
mosquitto_passwd -b passwordfile
./configs/enabledservices:
mosquitto:
container_name: mosquitto
hostname: mosquitto
image: eclipse-mosquitto
restart: unless-stopped
ports:
- 1883:1883
volumes:
- ./mosquitto/config:/mosquitto/config
- ./mosquitto/data:/mosquitto/data
- ./mosquitto/log:/mosquitto/logdocker compose up -d