我正在使用官方的RabbitMQ Docker镜像(https://hub.docker.com/_/rabbitmq/)
我在运行
后尝试编辑容器内的rabbitmq.config
文件
docker exec -it <container-id> /bin/bash
但是,这似乎对容器中运行的rabbitmq服务器没有影响。由于Docker启动了一个全新的实例,重启容器显然没有帮助。
所以我假设为Docker容器配置rabbitmq.config
的唯一方法是在容器开始运行之前设置它,我可以部分地使用图像支持的环境变量。
不幸的是,环境变量并不支持所有配置选项。例如,我想在{auth_mechanisms, ['PLAIN', 'AMQPLAIN', 'EXTERNAL']}
中设置rabbitmq.config
。
然后我找到了RABBITMQ_CONFIG_FILE
环境变量,它应该允许我指向我想用作conifg文件的文件。但是,我试过以下没有运气:
docker service create --name rabbitmq --network rabbitnet \
-e RABBITMQ_ERLANG_COOKIE='mycookie' --hostname = "{{Service.Name}}{{.Task.Slot}}" \
--mount type=bind,source=/root/mounted,destination=/root \
-e RABBITMQ_CONFIG_FILE=/root/rabbitmq.config rabbitmq
包含以下内容的默认rabbitmq.config
文件:
[ { rabbit, [ { loopback_users, [ ] } ] } ]
是容器启动后的内容
在Docker容器中配置rabbitmq.config
的最佳方法是什么?
答案 0 :(得分:14)
配置文件位于/etc/rabbitmq/rabbitmq.config
,所以如果您使用类似的东西安装自己的配置文件(我在这里使用docker-compose来设置图像)
volumes:
- ./conf/myrabbit.conf:/etc/rabbitmq/rabbitmq.config
应该这样做
答案 1 :(得分:0)
我可以使用以下bash
脚本运行带有挂载配置的RabbitMQ:
#RabbitMQ props
env=dev
rabbitmq_name=dev_rabbitmq
rabbitmq_port=5672
#RabbitMQ container
if [ "$(docker ps -aq -f name=${rabbitmq_name})" ]; then
echo Cleanup the existed ${rabbitmq_name} container
docker stop ${rabbitmq_name} && docker rm ${rabbitmq_name}
echo Create and start new ${rabbitmq_name} container
docker run --name ${rabbitmq_name} -d -p ${rabbitmq_port}:15672 -v $PWD/rabbitmq/${env}/data:/var/lib/rabbitmq:rw -v $PWD/rabbitmq/${env}/definitions.json:/opt/definitions.json:ro -v $PWD/rabbitmq/${env}/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro rabbitmq:3-management
else
echo Create and start new ${rabbitmq_name} container
docker run --name ${rabbitmq_name} -d -p ${rabbitmq_port}:15672 -v $PWD/rabbitmq/${env}/data:/var/lib/rabbitmq:rw -v $PWD/rabbitmq/${env}/definitions.json:/opt/definitions.json:ro -v $PWD/rabbitmq/${env}/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro rabbitmq:3-management
fi
我的config
目录
rabbitmq/dev
个文件
definitions.json
{
"rabbit_version": "3.7.3",
"users": [{
"name": "welib",
"password_hash": "su55YoHBYdenGuMVUvMERIyUAqJoBKeknxYsGcixXf/C4rMp",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": ""
}, {
"name": "admin",
"password_hash": "x5RW/n1lq35QfY7jbJaUI+lgJsZp2Ioh6P8CGkPgW3sM2/86",
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "administrator"
}],
"vhosts": [{
"name": "/"
}, {
"name": "dev"
}],
"permissions": [{
"user": "welib",
"vhost": "dev",
"configure": ".*",
"write": ".*",
"read": ".*"
}, {
"user": "admin",
"vhost": "/",
"configure": ".*",
"write": ".*",
"read": ".*"
}],
"topic_permissions": [],
"parameters": [],
"global_parameters": [{
"name": "cluster_name",
"value": "rabbit@98c821300e49"
}],
"policies": [],
"queues": [],
"exchanges": [],
"bindings": []
}
rabbitmq.config
[
{rabbit, [
{loopback_users, []},
{vm_memory_high_watermark, 0.7},
{vm_memory_high_watermark_paging_ratio, 0.8},
{log_levels, [{channel, warning}, {connection, warning}, {federation, warning}, {mirroring, info}]},
{heartbeat, 10}
]},
{rabbitmq_management, [
{load_definitions, "/opt/definitions.json"}
]}
].