获取镜像
# 查看可用的稳定版本
sudo docker search rabbitmq
sudo docker pull rabbitmq:3.7.13-management
sudo docker image ls |grep rabbitmq
创建数据卷
sudo mkdir -p /share/rabbitmq/data/config
sudo mkdir -p /share/rabbitmq/data/mnesia
sudo mkdir -p /share/rabbitmq/data/schema
服务编排
mkdir -p /share/rabbitmq && cd /share/rabbitmq
rm -rf /share/rabbitmq/docker-compose.yml
vi /share/rabbitmq/docker-compose.yml
编排文件如下:
version: '3'
services:
rabbitmq:
image: rabbitmq:3.7.13-management
hostname: rabbitmq
container_name: rabbitmq
ports:
- 5672:5672
- 15672:15672
volumes:
- /share/rabbitmq/data/config:/var/lib/rabbitmq/config
- /share/rabbitmq/data/mnesia:/var/lib/rabbitmq/mnesia
- /share/rabbitmq/data/schema:/var/lib/rabbitmq/schema
environment:
RABBITMQ_DEFAULT_VHOST: docker-node1
RABBITMQ_DEFAULT_USER: user1
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