Running Mosquitto in Docker
Revision as of 00:24, 3 June 2022 by Rhg (talk | contribs) (Created page with " Running Mosquitto MQTT broker in a Docker container is the advised method to deploy servers. *https://hub.docker.com/_/eclipse-mosquitto *https://www.youtube.com/watch?v=KKw3tUrX3d8 *'''https://www.youtube.com/watch?v=ABb-63y0Em4 CURRENT''' '''METHODOLOGY''' ===Install=== #https://docs.docker.com/engine/install/debian/#install-using-the-repository #'''sudo visudo''' ...ADD THIS LINE... '''''username'' ALL = NOPASSWD: /usr/bin/docker''' (https://stackoverflow.com/que...")
Running Mosquitto MQTT broker in a Docker container is the advised method to deploy servers.
- https://hub.docker.com/_/eclipse-mosquitto
- https://www.youtube.com/watch?v=KKw3tUrX3d8
- https://www.youtube.com/watch?v=ABb-63y0Em4 CURRENT METHODOLOGY
Install
- https://docs.docker.com/engine/install/debian/#install-using-the-repository
- sudo visudo ...ADD THIS LINE... username ALL = NOPASSWD: /usr/bin/docker (https://stackoverflow.com/questions/21659637/how-to-fix-sudo-no-tty-present-and-no-askpass-program-specified-error more info)
- Create local configuration files (see command below and Node-RED Flow)
- Build and start Docker image locally using command below.
sudo docker run -it -p 10883:10883 -p 9001:9001 --name=mqtt -v /home/pi/mqtt:/mosquitto/config -v /home/pi/mqtt/mqtt1.conf:/mosquitto/config/mosquitto.conf -v /home/pi/mqtt/aclfile.acl:/mosquitto/config/aclfile.acl -v /home/pi/mqtt/pwfile:/mosquitto/config/passwordfile eclipse-mosquitto:openssl
Starting
sudo docker restart mqtt
Node-RED Flow
[{"id":"c896650d2308013c","type":"tab","label":"Flow 4","disabled":false,"info":"","env":[]},{"id":"a270e07cd8944589","type":"mqtt in","z":"c896650d2308013c","name":"","topic":"#","qos":"0","datatype":"auto","broker":"6c0629962ffb1c73","nl":false,"rap":true,"rh":0,"inputs":0,"x":270,"y":660,"wires":[["a6cedcf7582829b2"]]},{"id":"881629b4b402addb","type":"mqtt out","z":"c896650d2308013c","name":"","topic":"test","qos":"0","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"6c0629962ffb1c73","x":490,"y":740,"wires":[]},{"id":"aaa773d83dec5212","type":"inject","z":"c896650d2308013c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":300,"y":740,"wires":[["881629b4b402addb"]]},{"id":"a6cedcf7582829b2","type":"debug","z":"c896650d2308013c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":660,"wires":[]},{"id":"9ff6e613a1dce1a8","type":"template","z":"c896650d2308013c","name":"Config","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"# Place your local configuration in /etc/mosquitto/conf.d/\n#\n# A full description of the configuration file is at\n# /usr/share/doc/mosquitto/examples/mosquitto.conf.example\n\nallow_anonymous true\n#password_file /etc/mosquitto/passwordfile\n#acl_file /etc/mosquitto/aclfile.acl\n\n\n#pid_file /var/run/mosquitto.pid\n\n#persistence true\n#persistence_location /var/lib/mosquitto/\n#log_dest file /var/log/mosquitto/mosquitto.log\n\npersistence true\npersistence_location /mosquitto/data/\nlog_dest file /mosquitto/log/mosquitto.log\n\n#include_dir /etc/mosquitto/conf.d\n\nlistener 10883\n\n#listener 8883\n#certfile /etc/letsencrypt/live/hw1.ddns.net/cert.pem\n#cafile /etc/letsencrypt/live/hw1.ddns.net/chain.pem\n#keyfile /etc/letsencrypt/live/hw1.ddns.net/privkey.pem\n\n#listener 8080\n#protocol websockets\n\n#listener 8081\n#protocol websockets\n#certfile /etc/letsencrypt/live/hw1.ddns.net/cert.pem\n#cafile /etc/letsencrypt/live/hw1.ddns.net/chain.pem\n#keyfile /etc/letsencrypt/live/hw1.ddns.net/privkey.pem","output":"str","x":490,"y":200,"wires":[["bceb525d1b4ba410"]]},{"id":"cf90ab78193f6ac2","type":"inject","z":"c896650d2308013c","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":300,"y":200,"wires":[["9ff6e613a1dce1a8","20b91b99a467d81d","6301a52df9e4e09b"]]},{"id":"bceb525d1b4ba410","type":"file","z":"c896650d2308013c","name":"","filename":"/home/pi/mqtt/mqtt1.conf","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":790,"y":200,"wires":[[]]},{"id":"6286ac39457d1d68","type":"comment","z":"c896650d2308013c","name":"Install Docker","info":"https://hub.docker.com/_/eclipse-mosquitto","x":290,"y":100,"wires":[]},{"id":"3020064cec4a4976","type":"comment","z":"c896650d2308013c","name":"RUN THIS COMMAND","info":"sudo docker run -it -p 10883:10883 -p 9001:9001 --name=mqtt -v /home/pi/mqtt:/mosquitto/config -v /home/pi/mqtt/mqtt1.conf:/mosquitto/config/mosquitto.conf -v /home/pi/mqtt/aclfile.acl:/mosquitto/config/aclfile.acl -v /home/pi/mqtt/pwfile:/mosquitto/config/passwordfile eclipse-mosquitto:openssl","x":720,"y":100,"wires":[]},{"id":"20b91b99a467d81d","type":"template","z":"c896650d2308013c","name":"Permissions","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"user admin\ntopic read #\ntopic write #","output":"str","x":510,"y":260,"wires":[["59fb6d115262793c"]]},{"id":"59fb6d115262793c","type":"file","z":"c896650d2308013c","name":"","filename":"/home/pi/mqtt/aclfile.acl","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":780,"y":260,"wires":[[]]},{"id":"6301a52df9e4e09b","type":"template","z":"c896650d2308013c","name":"Passwords","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"admin:$6$iBmph863NW4/69XA$6sBQaw5ORHEVDALHenSFZ4xNxU0uegQGuH8ze8PVY9opN0JkWrlP4pqYV+JEqdSj+ATeY0C8+CY+JbTov3kbbA==","output":"str","x":510,"y":320,"wires":[["9c2a576dd7637992"]]},{"id":"9c2a576dd7637992","type":"file","z":"c896650d2308013c","name":"","filename":"/home/pi/mqtt/pwfile","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":770,"y":320,"wires":[[]]},{"id":"8c7c23d0fc1dcfad","type":"comment","z":"c896650d2308013c","name":"Can then restart using","info":"sudo docker restart mqtt","x":960,"y":100,"wires":[]},{"id":"9acf17acef349724","type":"comment","z":"c896650d2308013c","name":"docker permissions","info":"sudo visudo\n\nADD THIS LINE...\npi ALL = NOPASSWD: /usr/bin/docker","x":490,"y":100,"wires":[]},{"id":"10ae80e9bec3769e","type":"inject","z":"c896650d2308013c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":300,"y":500,"wires":[["e10597dd965a80ae"]]},{"id":"e10597dd965a80ae","type":"exec","z":"c896650d2308013c","command":"sudo docker restart mqtt","addpay":"","append":"","useSpawn":"false","timer":"","winHide":true,"oldrc":false,"name":"","x":550,"y":500,"wires":[["e9c49bebf394b542"],["e9c49bebf394b542"],[]]},{"id":"e9c49bebf394b542","type":"debug","z":"c896650d2308013c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":500,"wires":[]},{"id":"df16fee8434bfa54","type":"exec","z":"c896650d2308013c","command":"sudo docker run -it -p 10883:10883 -p 9001:9001 --name=mqtt -v /home/pi/mqtt:/mosquitto/config -v /home/pi/mqtt/mqtt1.conf:/mosquitto/config/mosquitto.conf -v /home/pi/mqtt/aclfile.acl:/mosquitto/config/aclfile.acl -v /home/pi/mqtt/pwfile:/mosquitto/config/passwordfile eclipse-mosquitto:openssl","addpay":"","append":"","useSpawn":"false","timer":"","winHide":true,"oldrc":false,"name":"sudo docker run","x":520,"y":420,"wires":[["08b3d1b0507a9b6d"],["08b3d1b0507a9b6d"],[]]},{"id":"6e18e92c2369abda","type":"inject","z":"c896650d2308013c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":300,"y":420,"wires":[["df16fee8434bfa54"]]},{"id":"08b3d1b0507a9b6d","type":"debug","z":"c896650d2308013c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":420,"wires":[]},{"id":"6c0629962ffb1c73","type":"mqtt-broker","name":"docker","broker":"localhost","port":"10883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"5","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]