SoFunction
Updated on 2025-03-10

Example of implementation of Docker deployment of RocketMQ

1.1 Pull the rocketMQ image

docker pull apache/rocketmq:4.9.4

1.2  Create a nameserver data storage directory

rocketMQ is divided into two parts: nameserver and broker. The nameserver should be started first at startup, so we now create the nameserver log and data storage directory. This directory can be defined by ourselves, here I will put it in the data path

mkdir -p /app/rocketmq/logs /app/rocketmq/store

1.3 Build the namesrv container and start it

We have created the log and data storage path of the nameserver. At this time, we only need to hang it in the log and data path and execute the following command to start the nameserver.

docker run -d -p 9876:9876 --restart=always \
  -v /app/rocketmq/namesrv/logs:/home/rocketmq/logs \
  -v /app/rocketmq/namesrv/store:/home/rocketmq/store \
  --name mqnamesrv \
  --network rocketmq \
  -e"JAVA_OPT_EXT=-server -Xms512m -Xmx512m -Xmn512m" \
  apache/rocketmq:4.9.4 \
  sh mqnamesrv

2.1 Create a broker data storage path

Before operating this step, we have successfully started the nameserver, and then we will create a data mount directory and configuration file for the broker to ensure that the broker can start successfully.

mkdir -p /app/rocketmq/broker/logs  /app/rocketmq/broker/store /app/rocketmq/broker/conf

Description: logs: is the broker's log directory, store: is the broker's data directory (This directory requires all read and write permissions), conf is the broker configuration information directory

2.2 Create broker configuration file

We have just created the broker configuration directory (/data/rocketmqbroker/conf). Now we want to add a broker configuration file to the modified configuration directory, named it:

cd /app/rocketmq/broker/conf
vi 

Notice: Copy the information into the file, please note that you can modify brokerIP1 and change it to your server's IP address! Pay attention to modifying the namesrvAddr and change it to your nameserver's IP address!

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     /licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.


# Name of the clusterbrokerClusterName=DefaultCluster
# broker name, note that different configuration files are filled in differently. If you are using: broker-a,# In use: broker-bbrokerName=broker-a
# 0 means Master, > 0 means SlavebrokerId=0
# nameServer address, semicolon splitnamesrvAddr=192.168.18.200:9876
# Start the IP, if docker reports: connect to <192.168.0.120:10909> failed# Solution 1 Add a sentence (false);, Solution 2 BrokerIP1 Set the host IP, do not use docker internal IP#=false
brokerIP1=192.168.18.200

# When sending a message, automatically create topics that do not exist on the server, and the default number of queues createddefaultTopicQueueNums=4
# Whether to allow Broker to automatically create Topics, it is recommended to turn on offline and close online!  !  !  Here you look closely, it is false, false, falseautoCreateTopicEnable=true
# Whether Broker is allowed to automatically create subscription groups, it is recommended to turn on offline and close onlineautoCreateSubscriptionGroup=true
# Broker external service listening portlistenPort=10911
# Delete file time, default to 4 amdeleteWhen=04
# File retention time, default 48 hoursfileReservedTime=120
# commitLog The default size of each file is 1GmapedFileSizeCommitLog=1073741824
# ConsumeQueue Each file has 30W by default, and it is adjusted according to the business situation.mapedFileSizeConsumeQueue=300000
# destroyMapedFileIntervalForcibly=120000
# redeleteHangedFileInterval=120000
# Detect physical file disk spacediskMaxUsedSpaceRatio=88
# Storage path# storePathRootDir=/home/ztztdata/rocketmq-all-4.1.0-incubating/store
# commitLog storage path# storePathCommitLog=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/commitlog
# Consumption queue storage# storePathConsumeQueue=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/consumequeue
# Message index storage path# storePathIndex=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/index
# checkpoint file storage path# storeCheckpoint=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/checkpoint
# abort file storage path# abortFile=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/abort
# Restricted message sizemaxMessageSize=65536
# flushCommitLogLeastPages=4
# flushConsumeQueueLeastPages=2
# flushCommitLogThoroughInterval=10000
# flushConsumeQueueThoroughInterval=60000
# Broker's role# - ASYNC_MASTER Asynchronously copy Master# - SYNC_MASTER Synchronous dual write Master# - SLAVE
brokerRole=ASYNC_MASTER
# Wash the disk# - ASYNC_FLUSH Asynchronous Flush Disk# - SYNC_FLUSH Synchronous Flush DiskflushDiskType=ASYNC_FLUSH
# Number of message thread pools# sendMessageThreadPoolNums=128
# Number of message thread pools# pullMessageThreadPoolNums=128

2.3 Build the broker container and start it

docker run -d -p 10911:10911 -p 10909:10909 \
-v /app/rocketmq/broker/logs:/home/rocketmq/logs \
-v /app/rocketmq/broker/store:/home/rocketmq/store \
-v /app/rocketmq/broker/conf/:/home/rocketmq/rocketmq-4.9.4/conf/ \
--name rmqbroker \
-e "NAMESRV_ADDR=mqnamesrv:9876" \
 apache/rocketmq:4.9.4 \
sh mqbroker -n mqnamesrv:9876 \
-c  /home/rocketmq/rocketmq-4.9.4/conf/ autoCreateTopicEnable=true

-Console visual interface

3.1 Pull the rocketmq-console image

docker pull styletang/rocketmq-console-ng

3.2 Build the RocketMQ-Console container and start it

docker run -d --restart=always --name rocketmq-admin -e "JAVA_OPTS=-=mqnamesrv:9876 -=false"  -p 18080 :8080  styletang/rocketmq-console-ng

Note: Change the IP address after the message to your nameserver IP address!

This is the end of this article about the implementation example of Docker deploying RocketMQ. For more related content on Docker deploying RocketMQ, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!