docker mosquitto mqtt server
git clone https://github.com/toke/docker-mosquitto.git
sudo mkdir -p /docker/mqtt/log /docker/mqtt/config /docker/mqtt/data
sudo touch /docker/mqtt/log/mosquitto.log
sudo chmod 666 /docker/mqtt/log/mosquitto.log
cd docker-mosquitto/config/
sudo cp -a * /docker/mqtt/config/
sudo docker run -itd -p 1885:1883 -p 9001:9001 -v /docker/mqtt/config:/mqtt/config -v /docker/mqtt/log:/mqtt/log -v /docker/mqtt/data/:/mqtt/data/ --name mqtt toke/mosquitto
發送測試
docker exec mqtt mosquitto_pub -t hello -m "helloworld"

使用者認證
進入容器建立帳號密碼

# Place your local configuration in /mqtt/config/conf.d/
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /mqtt/data/
user mosquitto
#-----------need user auth---------
password_file /mqtt/config/passwd
allow_anonymous false
#---------------------------------
# Port to use for the default listener.
port 1883
log_dest file /mqtt/log/mosquitto.log
log_dest stdout
include_dir /mqtt/config/conf.d
mqtt 測試
docker exec mqtt mosquitto_pub -t hello -m "helloworld" -u user -P password

Last updated
Was this helpful?