Skip to content

The Mosquitto cheat sheet with Docker

Published: at 12:00 AM

Table of contents

Open Table of contents

Deploy a Mosquitto broker with docker

docker run -d --rm --name mqtt-broker -p 1883:1883 eclipse-mosquitto:1.6

Subscribe

docker run --rm -it eclipse-mosquitto:1.6 mosquitto_sub -v -h 172.17.0.1 -t '#'

Publish

docker run --rm -it eclipse-mosquitto:1.6 mosquitto_pub \
  -h 172.17.0.1 -t my-topic -m '{
  "msg": "hello world"
 }'

Subscribe by using current MQTT broker

docker exec -it mqtt-broker mosquitto_sub -v -t "#"

Publish by using current MQTT broker

docker exec -it mqtt-broker mosquitto_pub \
  -t my-topic -m '{
  "msg": "hello world"
 }'