2017-02-02 82 views
2

我使用的是官方的RabbitMQ多克爾圖像(https://hub.docker.com/_/rabbitmq/如何配置Docker容器內rabbitmq.config?

我試過編輯rabbitmq.config文件容器中運行

docker exec -it <container-id> /bin/bash

但之後,這似乎對無影響rabbitmq服務器在容器中運行。顯然重新啓動容器都於事無補,因爲碼頭工人開始一個完全新的實例。

因此,我認爲爲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嗎?

回答

7

配置文件住在/etc/rabbitmq/rabbitmq.config所以如果你有這樣的安裝你自己的配置文件(我在這裏使用泊塢窗,組成設置圖像)

volumes: 
- ./conf/myrabbit.conf:/etc/rabbitmq/rabbitmq.config 

應該這樣做

+1

工作了魅力。乾杯! – AmazingBergkamp

+1

聰明。謝謝! – bcattle

+0

我試圖用'COPY ./rabbitmq.config/etc/rabbitmq/rabbitmq.config'和'CMD [「rabbitmq-server」]''將配置文件添加到我自己的映像中,但似乎我添加的文件獲取被默認配置文件覆蓋。它可能是由「rabbit-server」命令創建的默認配置文件 –

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": "[email protected]" 
     }], 
     "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"} 
    ]} 
]. 
相關問題