Docker RabbitMQ 部署
Docker RabbitMQ 部署
RabbitMQ镜像安装
RabbitMQ 提供官方镜像,下载安装镜像方法如下:
[root@VM_0_14_centos ~]# docker pull rabbitmq:management
Trying to pull repository docker.io/library/rabbitmq ...
sha256:4cab9fe2eed84840e60ecb99b0a902883ef6d26f4dab2439d1119b6bdab4f2c8: Pulling from docker.io/library/rabbitmq
5667fdb72017: Already exists
d83811f270d5: Already exists
ee671aafb583: Already exists
7fc152dfb3a6: Already exists
511da93b5ba5: Pull complete
34ed6c3ce222: Pull complete
efe6df6279a7: Pull complete
3ca75f81239b: Pull complete
ded8ef942d92: Pull complete
c319281f11ad: Pull complete
b8109dc0ceda: Pull complete
1596b64dcd88: Pull complete
Digest: sha256:4cab9fe2eed84840e60ecb99b0a902883ef6d26f4dab2439d1119b6bdab4f2c8
Status: Downloaded newer image for docker.io/rabbitmq:management
创建并运行容器:
docker run -d --hostname my-rabbit --name rabbit -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -p 15672:15672 -p 5672:5672 rabbitmq:management
查看rabbit运行状况:
[root@VM_0_14_centos ~]# docker logs rabbit
容器运行正常,使用http://localhost:15672可以访问RabbitMQ控制台
以下方法是创建带有目录映射的方法:
1、docker下安装rabbitmq命令(不带目录映射):
docker run -itd –name rabbit -p 1884:1883 -p 5673:5672 -p 15673:15672 -p 25673:25672 -p 61614:61613 docker.io/rabbitmq:3-management
说明: rabbitmq:3-management是带有web管理功能的;lasted虽然是最近版,不一定带有web管理功能
2、配置实例:
192.168.0.238上docker实例:容器名:rabbit;
初始化默认账号:guest / guest
3、如何把容器中rabbitmq配置文件、数据存储目录、日志目录映射处理:
(1)首先创建一个没有目录映射的docker容器:
docker run -itd –name rabbit -p 1884:1883 -p 5673:5672 -p 15673:15672 -p 25673:25672 -p 61614:61613 docker.io/rabbitmq:3-management
(2)进入docker查看rabbitmq的相关目录:
[root@VM_0_14_centos ~]# docker exec -it 57659c0c243a /bin/bash
root@my-rabbit:/#
root@my-rabbit:/# ls
bin boot dev etc home lib lib64 media mnt opt plugins proc root run sbin srv sys tmp usr var
root@my-rabbit:/# cd /etc/rabbitmq/
root@my-rabbit:/etc/rabbitmq# cd /var/lib/rabbitmq/
root@my-rabbit:~# cd /var/log/rabbitmq/
root@my-rabbit:/var/log/rabbitmq#
配置文件目录:/etc/rabbitmq
数据存储目录:/var/lib/rabbitmq
日志目录:/var/log/rabbitmq
(3)把(2)中的三个目录从容器中复制到宿主机:
宿主机创建文件夹
[root@VM_0_14_centos local]# mkdir -p /usr/local/rabbitmq/lib
[root@VM_0_14_centos local]# mkdir -p /usr/local/rabbitmq/etc
[root@VM_0_14_centos local]# mkdir -p /usr/local/rabbitmq/log
复制文件到宿主机
[root@VM_0_14_centos local]# docker cp -a 57659c0c243a:/etc/rabbitmq /usr/local/rabbitmq/etc/
[root@VM_0_14_centos local]# docker cp -a 57659c0c243a:/var/lib/rabbitmq /usr/local/rabbitmq/lib/
[root@VM_0_14_centos local]# docker cp -a 57659c0c243a:/var/log/rabbitmq /usr/local/rabbitmq/log/
宿主机上创建rabbitmq用户
useradd rabbitmq
cd /home/
chmod -Rf rabbitmq:rabbitmq rabbitmq/
(4)目录映射:
-v /home/rabbitmq/etc/rabbitmq:/etc/rabbitmq -v /home/rabbitmq/lib/rabbitmq:/var/lib/rabbitmq -v /home/rabbitmq/log/rabbitmq/:/var/log/rabbitmq
4、创建带有目录映射的容器
docker run -itd –name rabbit -v /home/rabbitmq/etc/rabbitmq:/etc/rabbitmq -v /home/rabbitmq/lib/rabbitmq:/var/lib/rabbitmq -v /home/rabbitmq/log/rabbitmq/:/var/log/rabbitmq -p 1884:1883 -p 5673:5672 -p 15673:15672 -p 25673:25672 -p 61614:61613 docker.io/rabbitmq:3-management