The latest version of the official RocketMQ image, hub.docker.com, is 4.6.0, but the latest version of RocketMQ is now 4.9.2. So new versions from 4.6.0 up cannot be installed directly through DockerHub. RocketMQ will have to package the image locally.

Here I use RocketMQ version 4.9.2 for the full package deployment

1. Prepare for image production

1.1 Clone RocketMQ-Docker project code

#Official Docker address
git clone https://github.com/apache/rocketmq-docker.git
Copy the code

Execute the command above to clone the code for this project.

2. Build an image

There are two images that need to be built

  • Rocketmq – Dashboard Image (Web Console)
  • Rocketmq image (NameSrv and Broker)

2.1 RocketMQ Image Construction

cd image-build
sh build-image.sh RMQ-VERSION BASE-IMAGE
Copy the code

Use Dockerfile-centos file or Dockerfile-alpine file to build an IMAGE based on version and base-image (support centos, alpine).

Wait for the image to complete and then view it using the docker command

docker image ls
Copy the code

2.2 RocketMQ-Dashboard Image Construction

Just as we built the RocketMQ image, we built the RocketMQ-Dashboard image

cd image-build
sh build-image-dashboard.sh dashboard-VERSION BASE-IMAGE
Copy the code

Base-image supports only centos

Wait for the image build to complete.

docker image ls
Copy the code

3. The Docker – compose the installation

Why is docker-compose installed here? Because RocketMQ has three parts to install: Namesrv, Broker, and RocketMQ-Dashboard, docker-compose is easy to install.

3.1 Environment Preparation

Rocketmq-dashboard and RocketMQ images are available locally

3.2 RockerMQ Single-node deployment

3.2.1 Docker host environment of NameSrv

Configure the log path and storage path. (Mount path)

mkdir -p /root/rocketmq/data/namesrv/logs

mkdir -p /root/rocketmq/data/namesrv/store
Copy the code
3.2.2 Docker host environment for Broker

This section describes how to create logs and data stores and configure the mount paths for them

mkdir -p /root/rocketmq/data/broker/logs
mkdir -p /root/rocketmq/data/broker/store
mkdir -p /root/rocketmq/etc/broker
Copy the code
3.2.3 Broker configuration file creation
nano /root/rocketmq/etc/broker/broker.conf
Copy the code

The content of the document is as follows:

brokerClusterName = mxsm-docker
brokerName = mxsm-docker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
Docker environment needs to set host IP
BrokerIP1 = {docker host IP}
brokerIP1 = 192.168.43.128
Copy the code

For example, if the IP address queried by the command on the Docker host is 192.168.43.128, then this place is set to 192.168.43.128

3.2.4 Writing docker-compose file

Docker-compose: docker-compose: docker-compose: docker-compose: docker-compose: docker-compose: docker-compose: docker-compose: docker-compose: docker-compose: docker-compose

version: '3'
services:
  #Service for nameserver
  namesrv:
    image: Apacherocketmq/rocketmq: 4.9.2
    container_name: rocketmq-namesrv
    ports:
      - 9876: 9876
    environment:
      - JAVA_OPT_EXT=-server -Xms256m -Xmx256m -Xmn256m
    volumes:
      - /root/rocketmq/data/namesrv/logs:/root/logs
    command: sh mqnamesrv

  #Service for broker
  broker:
    image: Apacherocketmq/rocketmq: 4.9.2
    container_name: rocketmq-broker
    links:
      - namesrv
    depends_on:
      - namesrv
    ports:
      - 10909: 10909
      - 10911: 10911
      - 10912: 10912
    environment:
      - NAMESRV_ADDR=namesrv:9876
      - JAVA_OPT_EXT=-server -Xms512m -Xmx512m -Xmn256m
    volumes:
      - /root/rocketmq/data/broker/logs:/home/rocketmq/logs
      - /root/rocketmq/data/broker/store:/home/rocketmq/store
      - /root/rocketmq/etc/broker/broker.conf:/home/rocketmq/conf/broker.conf
    command: sh mqbroker -c /home/rocketmq/conf/broker.conf

  #Service for rocketmq-dashboard
  dashboard:
    image: Apache/rocketmq - dashboard: 1.0.0 - centos
    container_name: rocketmq-dashboard
    ports:
      - 8080: 8080
    links:
      - namesrv
    depends_on:
      - namesrv
    environment:
      - NAMESRV_ADDR=namesrv:9876
Copy the code

Run the command:

docker-compose -f ./docker-compose.yml up
Copy the code

Then look at what’s going on.

Rocketmq-broker exited with code 253 and no log was printed. The mount path may not have permissions. Add permission can.

Then log in to the Web console locally for verification

4. To summarize

  • In general, you can deploy docker according to the official RocketMQ-Docker project. There were some issues here, too. I was slow to start creating images with the official version, especially when it came to downloading and compiling. It is also possible to compile the project locally and then modify it to mirror it locally. This build has the advantage of being able to build an image of the version under development locally.
  • Official Docker-compose does not run the RocketMQ-Dashboard console.