LoginSignup
5
7

More than 3 years have passed since last update.

RaspberryPiにDockerでMosquittoを立てて、MQTTとWebsockets

Last updated at Posted at 2019-04-28

RaspberryPiでUSBを利用したDocker環境を作っていた時に、Pub/Subが要るなと思い、Reddis立てようかと考えましたが、そういえばよく使ってるMosquittoはDocker Hubで用意してくれてたりするんかな?と思って調べたらありまして、しかもオフィシャルで、なんとも簡単に環境構築ができましたのでご報告。

Mosquitto on Docker Hub
https://hub.docker.com/_/eclipse-mosquitto

イメージ取得

$ docker pull eclipse-mosquitto

永続データ

以下のディレクトリを永続的に利用し、マウントする必要があるのでホストに作成する

mosquiitto/config
mosquitto/data
mosquitto/log

mosquitto.conf

mosquitto/config/mosquitto.conf
が必要なので、gitから持ってきます。
https://github.com/eclipse/mosquitto

永続データについて、以下の様に書き換えます。

mosquitto.conf
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log

Websockets

上記の内容で起動できるのですが、MQTT over Websocketsできるように、以下のように設定を加えます。
mqttは1883, websocketsは9001に設定します。

mosquitto.conf
port 1883
listner 9001
protocol websockets

起動

$ docker run -itd --name mosquitto -v mosquitto:/mosquitto -p 1883:1883 -p 9001:9001 eclipse-mosquitto:latest

いやぁ、便利な世の中だねぇ...

5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7