Create the docker-comemage. yml file

Version: '3.8' services: rabbitmq1: image: rabbitMQ :management container_name: rabbitmq1 restart: always hostname: rabbitmq1 ports: - "5672:5672" - "15672:15672" volumes: - /opt/docker_volume/rabbitmq/rabbitmq1/data:/var/lib/rabbitmq - /opt/docker_compose_yml/rabbitmq/rabbitmq-ram.sh:/opt/rabbitmq/rabbitmq-ram.sh - /opt/docker_compose_yml/rabbitmq/rabbitmq-disk.sh:/opt/rabbitmq/rabbitmq-disk.sh - /opt/docker_compose_yml/rabbitmq/hosts:/etc/hosts environment: - RABBITMQ_DEFAULT_USER=root - RABBITMQ_DEFAULT_PASS=root - RABBITMQ_ERLANG_COOKIE=CURIOAPPLICATION networks: rabbitmq: Ipv4_address: 172.25.0.2 rabbitMQ2: image: rabbitMQ :management container_name: rabbitmq2 restart: always hostname: rabbitmq2 ports: - "5673:5672" volumes: - /opt/docker_volume/rabbitmq/rabbitmq2/data:/var/lib/rabbitmq - /opt/docker_compose_yml/rabbitmq/rabbitmq-ram.sh:/opt/rabbitmq/rabbitmq-ram.sh - /opt/docker_compose_yml/rabbitmq/rabbitmq-disk.sh:/opt/rabbitmq/rabbitmq-disk.sh - /opt/docker_compose_yml/rabbitmq/hosts:/etc/hosts environment: - RABBITMQ_ERLANG_COOKIE=CURIOAPPLICATION networks: Rabbitmq: ipv4_address: 172.25.0.3 RabbitMQ3: image: rabbitMQ :management container_name: rabbitmq3 restart: always hostname: rabbitmq3 ports: - "5674:5672" volumes: - /opt/docker_volume/rabbitmq/rabbitmq3/data:/var/lib/rabbitmq - /opt/docker_compose_yml/rabbitmq/rabbitmq-ram.sh:/opt/rabbitmq/rabbitmq-ram.sh - /opt/docker_compose_yml/rabbitmq/rabbitmq-disk.sh:/opt/rabbitmq/rabbitmq-disk.sh - /opt/docker_compose_yml/rabbitmq/hosts:/etc/hosts environment: - RABBITMQ_ERLANG_COOKIE=CURIOAPPLICATION networks: Rabbitmq: ipv4_address: 172.25.0.4 Networks: RabbitMQ: driver: bridge ipam: config: -subnet: "172.25.0.1/24" rabbitMQ: ipv4_address: 172.25.0.4 Networks: RabbitMQ: driver: bridge ipam: config: -subnet: "172.25.0.1/24"Copy the code

Create /opt/docker_compose_yml/rabbitmq/rabbitmq-ram.sh

Disk storage

rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@rabbitmq1
rabbitmqctl start_app
Copy the code

Create the /opt/docker_compose_yml/rabbitmq/rabbitmq-disk.sh script

Ram memory

rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster --ram rabbit@rabbitmq1
rabbitmqctl start_app
Copy the code

Create/opt/docker_compose_yml/rabbitmq/hosts

127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet FF00 ::0 ip6-mcastPrefix ff02::1 Ip6-allnodes FF02 ::2 IP6-allRouters 172.25.0.2 rabbitmq1 172.25.0.3 RabbitMQ2 172.25.0.4 Rabbitmq3Copy the code

Run the container

docker-compose up -d 
Copy the code

Go to the slave nodes (rabbitmq1, rabbitmq3,rabbitmq2 in this case) and start the script

Docker exec it rabbitmq1 bash bash /opt/rabbitmq/rabbitmq-ram.shCopy the code

The following provides a simple and direct way: Directly set the environment to start the cluster

Version: '3.8' services: rabbitmq1: image: rabbitMQ :management container_name: rabbitmq1 restart: always hostname: rabbitmq1 ports: - "5672:5672" - "15672:15672" volumes: - /opt/docker_volume/rabbitmq/rabbitmq1/data:/var/lib/rabbitmq environment: - RABBITMQ_DEFAULT_USER=root - RABBITMQ_DEFAULT_PASS=root - RABBITMQ_ERLANG_COOKIE=CURIOAPPLICATION - RABBITMQ_NODENAME:rabbitmq1 networks: - rabbitmq rabbitmq2: image: rabbitmq:management container_name: rabbitmq2 restart: always hostname: rabbitmq2 ports: - "5673:5672" volumes: - /opt/docker_volume/rabbitmq/rabbitmq2/data:/var/lib/rabbitmq environment: - RABBITMQ_ERLANG_COOKIE=CURIOAPPLICATION - RABBITMQ_NODENAME:rabbitmq2 - RABBITMQ_CLUSTERED=true - RABBITMQ_CLUSTER_WITH=rabbit@rabbitmq1 - RABBITMQ_RAM_NODE=true networks: - rabbitmq rabbitmq3: image: rabbitmq:management container_name: rabbitmq3 restart: always hostname: rabbitmq3 ports: - "5674:5672" volumes: - /opt/docker_volume/rabbitmq/rabbitmq3/data:/var/lib/rabbitmq environment: - RABBITMQ_ERLANG_COOKIE=CURIOAPPLICATION - RABBITMQ_NODENAME:rabbitmq3 - RABBITMQ_CLUSTERED=true - RABBITMQ_CLUSTER_WITH=rabbit@rabbitmq1 - RABBITMQ_RAM_NODE=true networks: - rabbitmq networks: rabbitmq: driver: bridge Name Command State Ports ------------------------------------------------------------------------------------------------------------------------ --------------------------------------------- rabbitmq1 docker-entrypoint.sh rabbi ... Up 15671/ TCP, 0.0.0.0:15672->15672/ TCP, 15691/ TCP, 15692/ TCP, 25672/ TCP, 4369/ TCP, 5671/ TCP, 0.0.0.0:5672->5672/ TCP rabbitmq2 docker-entrypoint.sh rabbi... Up 15671/ TCP, 0.0.0.0:15673->15672/ TCP, 15691/ TCP, 15692/ TCP, 25672/ TCP, 4369/ TCP, 5671/ TCP, 0.0.0.0:5673->5672/ TCP rabbitmq3 docker-entrypoint.sh rabbi... Up 15671/ TCP, 15672/ TCP, 15691/ TCP, 15692/ TCP, 25672/ TCP, 4369/ TCP, 5671/ TCP, 0.0.0.0:5674->5672/ TCPCopy the code