1.拉取两个镜像
docker pull apache/rocketmq
docker pull apacherocketmq/rocketmq-dashboard:latest
2.启动name server
docker run -d --name mqnamesrv --net=host apache/rocketmq ./mqnamesrv
3.创建路径和配置文件
# 创建broker挂载相关文件夹
mkdir -p /opt/rocketmq/logs
mkdir -p /opt/rocketmq/conf
mkdir -p /opt/rocketmq/store
vim /opt/rocketmq/conf/broker.conf
配置文件写入以下内容:
#nameserver的外网ip地址,这个一般为9876端口,这个配置项也可以不要,启动的时候指定
#我这里只是单机安装, 没有集群, 所以配置为本地IP
namesrvAddr=127.0.0.1:9876
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1 = 127.0.0.1
listenPort=10911
4.启动broker
docker run -d --net=host -v /opt/rocketmq/logs:/root/logs -v /opt/rocketmq/store:/root/store -v /opt/rocketmq/conf/broker.conf:/home/rocketmq/rocketmq-5.1.4/conf/broker.conf --name rmqbroker -p 9876:9876 apache/rocketmq sh mqbroker -n ip:9876 -c /home/rocketmq/rocketmq-5.1.4/conf/broker.conf
5.启动rocketmq-dashboard (可视化管理工具)
docker run -d --net=host --name rocketmq-dashboard -e "JAVA_OPTS=-Drocketmq.namesrv.addr=127.0.0.1:9876" -t apacherocketmq/rocketmq-dashboard:latest
6.[注意]
以上三个容器都是以host方式启动的, 所以不需要映射端口, 如果不是这个网络模式的话, 相应的IP需要指定为外网IP