编写 docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
version: '3'
services:
rabbitmq:
image: rabbitmq:3.8.3-management
container_name: rabbitmq
restart: always
hostname: myRabbitmq
ports:
- 15672:15672
- 5672:5672
volumes:
- ./data:/var/lib/rabbitmq
environment:
- RABBITMQ_DEFAULT_USER=root
- RABBITMQ_DEFAULT_PASS=root
参考文档:https://registry.hub.docker.com/_/rabbitmq/

浏览器访问

浏览器访问 ip:15672 即可,用户名,密码输入 root 登录。

注意

  1. application.yml 文件中推荐为 docker 容器设置 hostname,因为 rabbitmq 默认使用 hostname 作为存储数据的节点名,设置 hostname 可以避免生成随机的节点名,方便追踪数据。官网原文如下

     One of the important things to note about RabbitMQ is that it stores data based on what it calls the "Node Name", which defaults to the hostname. What this means for usage in Docker is that we should specify -h/--hostname explicitly for each daemon so that we don't get a random hostname and can keep track of our data:
    
  2. RABBITMQ_DEFAULT_USERRABBITMQ_DEFAULT_PASS 用来设置超级管理员的账号和密码,如果不设置,默认都是 guest

  3. docker 镜像使用像这样 rabbitmq:3.8.3-management 带有后缀 -management 的镜像,之前使用没带这个后缀的镜像,网页会访问失败。

用户设置与 virtual host 配置

参考文档:https://www.cnblogs.com/juncaoit/p/8570627.html