下载镜像

  1. docker pull rabbitmq:3.8-management

编写docker-compose.yml

  1. version: '3'
  2. services:
  3. rabbit:
  4. image: rabbitmq:3.8-management
  5. hostname: rabbit
  6. container_name: "rabbitmq"
  7. restart: always
  8. ports:
  9. - "8303:5672"
  10. - "8304:15672"
  11. environment:
  12. - RABBITMQ_DEFAULT_USER=root
  13. - RABBITMQ_DEFAULT_PASS=l3c^cYa4
  14. volumes:
  15. - /home/data/rabbitmq:/var/lib/rabbitmq

端口号说明:

  • 5672:用于 amqp 协议通信,用于程序连接 rabbitmq 使用。
  • 15672:用于 rabbitmq 的 web 管控台访问端口。

RABBITMQ_DEFAULT_USER和RABBITMQ_DEFAULT_PASS就是设置web管控台的默认用户名和密码。

启动服务

  1. docker-compose up -d

启动web监控插件

进入容器

  1. docker exec -it rabbitmq bash

执行启用插件命令

  1. rabbitmq-plugins enable rabbitmq_management

响应信息如下:

  1. Enabling plugins on node rabbit@rabbit:
  2. rabbitmq_management
  3. The following plugins have been configured:
  4. rabbitmq_management
  5. rabbitmq_management_agent
  6. rabbitmq_prometheus
  7. rabbitmq_web_dispatch
  8. Applying plugin configuration to rabbit@rabbit...
  9. Plugin configuration unchanged.