docker-compose安裝rabbitmq

編寫時間:2020-05-08

參考文檔:docker安裝rabbitmq

1. 編寫docker-compose.yml

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

2. 瀏覽器訪問 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_USER  和  RABBITMQ_DEFAULT_PASS 用來設置超級管理員的帳號和密碼,如果不設置,默認都是 guest

3.  docker鏡像使用像這樣 rabbitmq:3.8.3-management  帶有後綴 -management的鏡像,之前使用沒帶這個後綴的鏡像,網頁訪問失敗,如下圖。