Docker安装RabbitMQ

一、下载镜像

docker pull rabbitmq:3.8-management

二、启动容器

应用访问端口5672,web访问端口15672

version: '3'
services:
  rabbitmq:
    image: rabbitmq:3.8-management
    container_name: rabbitmq
    restart: always
    hostname: rabbitmq
    ports:
      - 5672:5672
      - 15672:15672
    volumes:
      - /home/qiang/data/rabbitmq:/var/lib/rabbitmq
    environment:
      - RABBITMQ_DEFAULT_USER=root
      - RABBITMQ_DEFAULT_PASS=123456
mkdir -p /home/qiang/data/rabbitmq/conf/
docker cp rabbitmq:/etc/rabbitmq/rabbitmq.conf /home/qiang/data/rabbitmq/conf/rabbitmq.conf

rabbitmq.conf

loopback_users.guest = false
listeners.tcp.default = 5672
default_pass = SjHlvlQVevNU0x8G
default_user = rabbitmq
management.tcp.port = 15672
management.path_prefix = /rabbitmq
version: '3'
services:
  rabbitmq:
    image: rabbitmq:3.8-management
    container_name: rabbitmq
    restart: always
    hostname: rabbitmq
    ports:
      - 5672:5672
      - 15672:15672
    volumes:
      - /home/qiang/data/rabbitmq/data:/var/lib/rabbitmq
      - /home/qiang/data/rabbitmq/conf/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf

注意:

  1. application.yml文件中推荐为docker容器设置hostname,因为rabbitmq默认使用hostname作为存储数据的节点名,设置hostname可以避免生成随机的节点名,方便追踪数据。
  2. RABBITMQ_DEFAULT_USER 和 RABBITMQ_DEFAULT_PASS 用来设置超级管理员的账号和密码,如果不设置,默认都是 guest。
  3. docker镜像使用带有后缀-management的镜像,就可以访问页面,否则不能访问。

image-20220223000223482

三、整合应用

pom.xml


<dependency>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-amqpartifactId>
dependency>

application.yml

spring:
  application:
    name: rabbitmq-service
  rabbitmq:
    host: 192.168.1.51
    port: 5627
    username: root
    password: 123456

作者(Author):小强崽
来源(Source):https://www.wuduoqiang.com/archives/Docker安装RabbitMQ
协议(License):署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
版权(Copyright):商业转载请联系作者获得授权,非商业转载请注明出处。 For commercial use, please contact the author for authorization. For non-commercial use, please indicate the source.

你可能感兴趣的:(Docker,docker)