docker-mosquitto部署学习
之前有写实体机MQTT服务器搭建(mosquitto) | Regen的流程,容器化部署是大趋势,也不能落下。
如果你对mqtt的数据存储有兴趣的话不妨看看。
看了dockerhub的镜像,选择了eclipse-mosquitto:2.0.22-openssl
拉取镜像
1 | docker pull eclipse-mosquitto:2.0.22-openssl |
准备文件
准备mosquitto.conf
passwordfile
mosquitto.conf
1 | # 监听端口 |
passwordfile
用于使用账号密码登录,用以下命令进行创建该文件
1 | docker run --rm -it -v $(pwd):/mosquitto/config eclipse-mosquitto:2.0.22-openssl mosquitto_passwd -c /mosquitto/config/passwordfile admin |
创建好了会出现在当前目录
docker-compose 持久化部署
1 | version: "3.8" |
测试案例
使用docker exec -it mosquitto sh
进入容器内命令行工具。之后才能执行以下命令。
1 | mosquitto_pub -h 127.0.0.1 -p 1883 -t test -m "hello" |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment