docker mqqt 安装

安装

bash 复制代码
cd /data/mqqt/

目录准备

mkdir /data/mqqt/mosquitto/config/

#vim Dockerfile

bash 复制代码
# 使用官方Eclipse Mosquitto镜像作为基础镜像
FROM eclipse-mosquitto:latest
# 复制配置文件到容器内
COPY mosquitto.conf /data/mqqt/mosquitto/config/mosquitto.conf

# 暴露默认的MQTT端口和WebSocket端口
EXPOSE 1883
EXPOSE 9001
# 运行Mosquitto服务
CMD ["/usr/sbin/mosquitto", "-c", "/data/mqqt/mosquitto/config/mosquitto.conf"]

#vim mosquitto.conf

#添加你的配置内容,例如:

bash 复制代码
listener 1883
allow_anonymous true
listener 9001
protocol websockets

ip

bash 复制代码
192.168.3.100

构建Docker镜像

bash 复制代码
docker build -t custom-mosquitto .

运行Docker容器

使用以下命令运行刚才构建的Docker镜像,并确保容器对外开放端口:

bash 复制代码
docker run -d --name mosquitto -p 1883:1883 -p 9001:9001 custom-mosquitto

测试MQTT代理

bash 复制代码
sudo apt-get install mosquitto-clients

使用mosquitto_pub和mosquitto_sub测试发布和订阅消息:

topic

test/topic
测试发布下消息

bash 复制代码
mosquitto_pub -h 192.168.3.100 -t test/topic -m "Hello MQTT"

测试接收消息

bash 复制代码
mosquitto_sub -h 192.168.3.100 -t test/topic
相关推荐
少妇的美梦18 小时前
logstash教程
运维
容器魔方18 小时前
Bloomberg 正式加入 Karmada 用户组!
云原生·容器·云计算
chen94518 小时前
k8s集群部署vector日志采集器
运维
chen94518 小时前
aws ec2部署harbor,使用s3存储
运维
muyun28001 天前
Docker 下部署 Elasticsearch 8 并集成 Kibana 和 IK 分词器
elasticsearch·docker·容器
東雪蓮☆1 天前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
qq_264220891 天前
LVS负载均衡群集和LVS+Keepalived群集
运维·负载均衡·lvs
乌萨奇也要立志学C++1 天前
【Linux】进程概念(二):进程查看与 fork 初探
linux·运维·服务器
雨落Liy1 天前
Nginx 从入门到进阶:反向代理、负载均衡与高性能实战指南
运维·nginx·负载均衡
Nazi61 天前
k8s的dashboard
云原生·容器·kubernetes