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
相关推荐
Kratzdisteln15 分钟前
【linux】
linux·运维·服务器
Filotimo_18 分钟前
Nginx 的概念
运维·nginx
Elieal21 分钟前
常用的 Linux 命令
linux·运维·服务器
装不满的克莱因瓶27 分钟前
【2026最新 架构环境安装篇三】Docker安装RabbitMQ4.x详细教程
linux·运维·docker·容器·架构·rabbitmq
音无八重36 分钟前
Linux(Ubuntu)下无法连接ppa.launchpadcontent.net的解决方法
linux·运维·ubuntu
YongCheng_Liang1 小时前
MySQL 高级特性深度解析:从索引优化到高可用架构
运维·数据库·mysql
Run_Teenage2 小时前
认识ELF格式文件,理解库链接过程
linux·运维·服务器
Leon-zy2 小时前
【Linux】Linux下手动添加的systemctl服务使用journalctl查看无日志或排版乱
linux·运维·服务器
软件工程小施同学2 小时前
区块链论文速读 CCF A--TDSC 2025 (3)
运维·服务器·区块链
Q16849645152 小时前
红帽Linux-监控和管理Linux进程
linux·运维·服务器