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
相关推荐
dessler7 分钟前
代理服务器-LVS的DR模式
linux·运维·云计算
cui_win1 小时前
每日一令:Linux 极简通关指南 - 汇总
linux·运维·服务器
知星小度S2 小时前
Linux权限探秘:驾驭权限模型,筑牢系统安全
linux·运维·服务器
Kaede65 小时前
如何应对Linux云服务器磁盘空间不足的情况
linux·运维·服务器
Kookoos8 小时前
Dynamics 365 Finance + Power Automate 自动化凭证审核
运维·自动化·dynamics 365·power automate
努力学习的小廉11 小时前
深入了解linux系统—— 进程池
linux·运维·服务器
MickeyCV11 小时前
使用Docker部署MySQL&Redis容器与常见命令
redis·mysql·docker·容器·wsl·镜像
秃头菜狗11 小时前
各个主要目录的功能 / Linux 常见指令
linux·运维·服务器
棠十一12 小时前
Rabbitmq
分布式·docker·rabbitmq
jiunian_cn13 小时前
【Linux】centos软件安装
linux·运维·centos