Docker安装RocketMQ
安装 Redis
安装dashboard
- 下载clone dashboard(源码)
- 下载dashboard(现成的jar)
- 若下载现成的jar就不用maven打包,只需要将jar放在Dockerfile目录下的target目录下,或者改Dockerfile都行
- 若是用的源码,需要用maven打包,然后将下面的Dockerfile放在项目根目录下
Dockerfile 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20使用官方Java运行时环境作为基础镜像
FROM java:8
设置时区(可选,根据你的需要)
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
假设你的jar文件和Dockerfile在同一目录下
COPY target/rocketmq-dashboard-1.0.1-SNAPSHOT.jar /app-nq/rocketmq-dashboard.jar
设置工作目录为/
WORKDIR /app-nq
定义容器启动时执行的命令
使用exec形式运行jar包,这样可以让容器成为该进程的主进程
这样可以确保Docker可以正确发送信号和回收进程
CMD ["java", "-jar", "/app-nq/rocketmq-dashboard.jar"]
暴露应用的端口,假设你的Spring Boot应用运行在8080端口
EXPOSE 8082 - 执行
docker build -t rocketmq-dashboard:1.0.1 .
命令构建镜像
docker-compose编排容器
创建文件
E:/Docker/rocketmq/5.0.0/conf/broker.conf
broker.conf 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 不加无法访问
brokerIP1=192.168.2.8
# 自动创建主题
autoCreateTopicEnable=true
# nameserver地址
namesrvAddr=192.168.2.8:9876编写
docker-compose.yml
docker-compose.yml 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42version: '3.8'
services:
namesrv:
image: apache/rocketmq:5.0.0
container_name: rocketmq-namesrv
ports:
- 9876:9876
networks:
- rocketmq
command: sh mqnamesrv
broker:
image: apache/rocketmq:5.0.0
container_name: rocketmq-broker
ports:
- 10909:10909
- 10911:10911
- 10912:10912
environment:
- NAMESRV_ADDR=rocketmq-namesrv:9876
depends_on:
- namesrv
networks:
- rocketmq
volumes:
- "E:/Docker/rocketmq/5.0.0/conf/broker.conf:/home/rocketmq/rocketmq-5.0.0/conf/broker.conf"
command: sh mqbroker -c /home/rocketmq/rocketmq-5.0.0/conf/broker.conf
dashboard:
image: rocketmq-dashboard:1.0.1
container_name: rocketmq-dashboard
ports:
- 9875:8082
networks:
- rocketmq
volumes:
- "E:/Docker/rocketmq/dashboard/:/app-nq/"
command: java -jar /app-nq/rocketmq-dashboard.jar
networks:
rocketmq:
driver: bridge执行
docker-compose -p rocketmq up -d
编排容器