获取镜像

  1. # 查看可用的稳定版本
  2. sudo docker search rabbitmq
  3. sudo docker pull rabbitmq:3.7.13-management
  4. sudo docker image ls |grep rabbitmq

创建数据卷

  1. sudo mkdir -p /share/rabbitmq/data/config
  2. sudo mkdir -p /share/rabbitmq/data/mnesia
  3. sudo mkdir -p /share/rabbitmq/data/schema

服务编排

  1. mkdir -p /share/rabbitmq && cd /share/rabbitmq
  2. rm -rf /share/rabbitmq/docker-compose.yml
  3. vi /share/rabbitmq/docker-compose.yml

编排文件如下:

  1. version: '3'
  2. services:
  3. rabbitmq:
  4. image: rabbitmq:3.7.13-management
  5. hostname: rabbitmq
  6. container_name: rabbitmq
  7. ports:
  8. - 5672:5672
  9. - 15672:15672
  10. volumes:
  11. - /share/rabbitmq/data/config:/var/lib/rabbitmq/config
  12. - /share/rabbitmq/data/mnesia:/var/lib/rabbitmq/mnesia
  13. - /share/rabbitmq/data/schema:/var/lib/rabbitmq/schema
  14. environment:
  15. RABBITMQ_DEFAULT_VHOST: docker-node1
  16. RABBITMQ_DEFAULT_USER: user1
  17. RABBITMQ_DEFAULT_PASS: pass1

服务构建

cd /share/rabbitmq
sudo docker-compose -f docker-compose.yml build --no-cache # 不带缓存构建(只创建镜像,不会启动容器)
sudo docker-compose -f docker-compose.yml up -d  # 构建后运行
sudo docker-compose -f docker-compose.yml up --build # 跟踪方式构建,可用于调试
sudo docker-compose -f docker-compose.yml stop # 停止
sudo docker-compose -f docker-compose.yml down # 移除

验证

cd /share/rabbitmq
# 查看进程
sudo docker-compose -f docker-compose.yml ps
sudo docker-compose exec rabbitmq /bin/bash
# 查看日志
sudo docker logs rabbitmq 
sudo docker logs -f -t --tail=50 rabbitmq 
# 查看网络
sudo docker network ls
sudo docker inspect rabbitmq