Mosquitto Docker

Eclipse Mosquitto is an open source implementation of a server for versions 5, 3.1.1, and 3.1 of the MQTT protocol. Main homepages: http://mosquitto.org/

Docker

mkdir -p ./mosquitto/config ./mosquitto/data ./mosquitto/log
chmod -R 755 ./mosquitto
vi ./mosquitto/config/mosquitto.conf
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
docker run -d --name=mosquitto \
-p 1883:1883 -p 9001:9001 \
-v $PWD/mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf \
-v $PWD/mosquitto/data:/mosquitto/data \
-v $PWD/mosquitto/log:/mosquitto/log \
eclipse-mosquitto:1.6.15

Docker Compose

mosquitto.yml

SSL/TLS

vi ./mosquitto/config/mosquitto.conf

port 8883
cafile /etc/mosquitto/ssl/xxx.crt
certfile /etc/mosquitto/ssl/xxx.crt
keyfile /etc/mosquitto/ssl/xxx.key

mosquitto-ssl.yml

Quick start

mosquitto_sub -t 'test/topic' -v
mosquitto_pub -t 'test/topic' -m 'hello world'