1. 获取镜像
# 查看可用的稳定版本
sudo docker search rabbitmq
sudo docker pull rabbitmq:management
sudo docker pull rabbitmq:3-management
sudo docker pull rabbitmq:3.7.7-management-alpine
sudo docker pull rabbitmq:3.7.13-management
sudo docker image ls |grep rabbitmq
2. 创建数据卷
sudo mkdir -p /share/rabbitmq/data
3. 启动容器
# 方法1
sudo docker run -d --name=rabbitmq \
-p 5672:5672 \
-p 15672:15672 \
rabbitmq:management
# 方法2
# 初始化密码(默认:guest/guest)
sudo docker run -d --name rabbitmq \
--hostname rabbitmq \
-p 5672:5672 \
-p 15672:15672 \
-e RABBITMQ_DEFAULT_USER=user1 \
-e RABBITMQ_DEFAULT_PASS=pass1 \
rabbitmq:3-management
# 方法3
sudo docker run -d --name rabbitmq \
--hostname rabbitmq \
-p 5672:5672 \
-p 15672:15672 \
-v "/share/rabbitmq/data:/var/lib/rabbitmq" \
-e RABBITMQ_DEFAULT_VHOST=docker-node1 \
-e RABBITMQ_DEFAULT_USER=user1 \
-e RABBITMQ_DEFAULT_PASS=pass1 \
rabbitmq:3.7.13-management
sudo docker start rabbitmq
sudo docker restart rabbitmq
sudo docker stop rabbitmq
sudo docker rm rabbitmq