-
创建需要映射的目录
# mkdir -p ~/rabbitmq/{etc,lib,var/{lib,log}} mkdir -p ~/rabbitmq/{etc,log}- 1
- 2
-
创建一个没有目录映射的容器
docker run -itd --name rabbit -p 5672:5672 -p 15672:15672 -p 25673:25672 rabbitmq:3.11-management- 1
-
复制容器配置文件到本地
docker cp -a f20dfe09b150:/etc/rabbitmq ~/rabbitmq/etc docker cp -a f20dfe09b150:/var/log/rabbitmq ~/rabbitmq/log- 1
- 2
-
停止rabbit
docker stop rabbit docker rm rabbit- 1
- 2
-
修改日志文件输出
默认控制台输出
vim ~/rabbitmq/etc/conf.d/10-defaults.conf log.console = false # 默认true- 1
- 2
-
启动rabbit MQ
docker run -itd --name rabbit -p 5672:5672 -p 15672:15672 -p 25673:25672 \ -v ~/rabbitmq/etc:/etc/rabbitmq \ -v ~/rabbitmq/log:/var/log/rabbitmq \ rabbitmq:3.11-management- 1
- 2
- 3
- 4
-
查看日志
docker logs -f --tail=100 rabbit tail -f ~/rabbitmq/log/rabbit@ed16387764ea.log- 1
- 2
docker安装rabbitmq遇到Permission denied
touch: cannot touch ''/etc/rabbitmq/rabbitmq.conf'': Permission denied
touch: cannot touch ''/etc/rabbitmq/rabbitmq.conf'': Permission denied
- 1
- 2
网上解决办法:在挂载目录后多加一个–privileged=true参数 ,经测试几次无效;
解决:
-
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- 1
-
进入docker查看rabbitmq的相关目录
- docker exec -it rabbit /bin/bash
- 配置文件目录:/etc/rabbitmq
- 数据存储目录:/var/lib/rabbitmq
- 日志目录:/var/log/rabbitmq
-
从容器中复制到宿主机
mkdir -p /home/rabbitmq/lib mkdir -p /home/rabbitmq/etc mkdir -p /home/rabbitmq/log docker cp -a 容器ID:/var/lib/rabbitmq /home/rabbitmq/lib/ docker cp -a 容器ID:/etc/rabbitmq /home/rabbitmq/etc/ docker cp -a 容器ID:/var/log/rabbitmq /home/rabbitmq/log/ docker cp -a cc31fe09b295:/etc/rabbitmq ~/docker/rabbit/etc docker cp -a cc31fe09b295:/var/lib/rabbitmq ~/docker/rabbit/lib/ docker cp -a cc31fe09b295:/var/log/rabbitmq ~/docker/rabbit/log/- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
-
启动
配置文件和日志映射到本地
-- 日志级别 docker run -itd --name rabbit01 -e RABBITMQ_LOGS=debug -v ~/docker/rabbit/etc/rabbitmq:/etc/rabbitmq -v ~/docker/rabbit/lib/rabbitmq:/var/lib/rabbitmq -v ~/docker/rabbit/log/rabbitmq:/var/log/rabbitmq -p 1884:1883 -p 5673:5672 -p 15673:15672 -p 25673:25672 -p 61614:61613 rabbitmq:3.11-management- 1
- 2
docker restart rabbit01 -- 检查日志映射到本地是否正确配置 docker inspect rabbit01 -- 查看日志 docker logs -f rabbit01 tail -f ~/docker/rabbit/log/rabbitmq/debug- 1
- 2
- 3
- 4
- 5
- 6
注意权限问题:如果docker logs -f rabbit01查看生成的文件有权限问题,可手动创建日志文件~/docker/rabbit/log/rabbitmq/debug,并设置读写权限