#Docker RabbitMQ Container
A docker container that is highly configurable with environment variables
###Contents
Advanced Environment Variables
##Environment Variables
Simple variables are easy to pass into the container for use by rabbitmq
#####RABBITMQ_USER
- default: "rabbit"
#####RABBITMQ_PASSWORD
- default: "rabbit"
#####RABBITMQ_VHOST
- default: "/"
#####RABBITMQ_ERLANG_COOKIE
- default: "iamnotasecret"
#####RABBITMQ_PORT
- default: 5672
#####RABBITMQ_NODENAME
- default: 'hostname'
##Clustering
Clustering can be setup by passing the RABBITMQ_CLUSTER_NODES or CLUSTER_NODES_SAFE environment variables as a list, for example
RABBITMQ_CLUSTER_NODES=[ 'rabbit@ip-10-0-0-43', 'rabbit@ip-10-0-22-37' ]
These are injected directly into rabbitmq.config. Note that clustering relies on,
-
The hostname being equal to the node name. This is commonly done by setting the hostname so that something like the below would set up clustering automatically.
hostname -s # Should output ip-10-0-0-43 on the corresponding node # On the host machine docker run --name rabbitmq --hostname ip-10.0.0.43 -e CLUSTER_NODES=[ 'rabbit@ip-10-0-0-16', 'rabbit@ip-10-0-22-37' ] rabbitmq
-
The nodes addresses must be resolvable
ping ip-10-0-0-43
-
The erlang cookie must be equal on all clustering nodes
curl /var/lib/rabbitmq/.erlang_cookie
##Advanced Environment Variables
There is also a series of more advanced environment variables possible to allow setup of more complex options. These are sections of JSON in the format expected by rabbitmq's definitions format. Some examples are given below. To see the format in more detail you can go to a rabbitmq management web interfaces and download broker definitions. The currently supported elements are defined below with examples. Note that we've used upper-case to show which parts of the environment variables are used for keys and so, should not be changes, lower case ones are not matched and can be altered by the user.
####If using automated setup it is advised to override the guest user password and permissions
#####RABBITMQ_CLUSTER_NODES
RABBITMQ_CLUSTER_NODES='[rabbit@rabbit01, rabbit@rabbit02]'
#####RABBITMQ_MANAGEMENT_USERS_*
RABBITMQ_MANAGEMENT_USERS_bob='{"name":"bob","password":"changeme","tags":"administrator"}' \
#####RABBITMQ_MANAGEMENT_VHOSTS_*
RABBITMQ_MANAGEMENT_VHOSTS_myvhost='{"name":"/my-vhost"}'
#####RABBITMQ_MANAGEMENT_POLICIES_*
RABBITMQ_MANAGEMENT_POLICIES_mypolicy='{"vhost":"/my-vhost", "name":"my-policy","pattern":"^ha\.", "definition":{"ha-mode":"all"}}'
#####RABBITMQ_MANAGEMENT_USERS_*
RABBITMQ_MANAGEMENT_PERMISSIONS_bob='{"user":"bob","vhost":"/my-vhost","configure":".*","write":".*","read":".*"}'
#####RABBITMQ_MANAGEMENT_EXCHANGES_*
RABBITMQ_MANAGEMENT_EXCHANGES_exchange1='{"name":"exchange1","vhost":"vhost1","type":"topic","durable":true,"auto_delete":false,"internal":false,"arguments":{}}'
-e \
#####RABBITMQ_MANAGEMENT_QUEUES_*
RABBITMQ_MANAGEMENT_QUEUES_haqueue1='{"name":"haqueue1, "vhost":"vhost1", "durable":true, "auto_delete":false, "arguments":{"x-dead-letter-exchange":"haqueue1-retry-requeue", "x-message-ttl":300000}}"'
#####RABBITMQ_MANAGEMENT_BINDINGS_*
RABBITMQ_MANAGEMENT_BINDINGS_bindings1='{"source":"exchange1", "vhost":"vhost1", "destination":"haqueue1", "destination_type":"queue", "routing_key":"testkey", "arguments":{}}'
Code Example
Using the test script we can insert some more advanced variables
docker run \
-e RABBITMQ_MANAGEMENT_POLICIES_policy1='{"vhost":"/vhost1", "pattern": "test1", "definition": {"dead-letter-exchange":"exchange1","ha-mode":"all"}}' \
-e RABBITMQ_MANAGEMENT_POLICIES_policy2='{"vhost":"/vhost2", "pattern": "test2", "definition": {"dead-letter-exchange":"exchange2","ha-mode":"all"}}' \
-e RABBITMQ_MANAGEMENT_USERS_user1='{"name":"user1","password":"changeme","tags":"administrator"}' \
-e RABBITMQ_MANAGEMENT_USERS_user2='{"name":"user2","password":"changeme","tags":"administrator"}' \
-e RABBITMQ_MANAGEMENT_VHOSTS_vhost1='{"name":"/vhost1"}' \
-e RABBITMQ_MANAGEMENT_VHOSTS_vhost2='{"name":"/vhost2"}' \
-e RABBITMQ_MANAGEMENT_PERMISSIONS_permissions1='{"user":"user1","vhost":"/vhost1","configure":".*","write":".*","read":".*"}' \
-e RABBITMQ_MANAGEMENT_PERMISSIONS_permissions2='{"user":"user2","vhost":"/vhost2","configure":".*","write":".*","read":".*"}' \
-e RABBITMQ_MANAGEMENT_QUEUES_queue1='{"name":"queue1","vhost":"/vhost1","durable":true,"auto_delete":false,"arguments":{"x-dead-letter-exchange":"queue1-retry-requeue","x-message-ttl":300000}}' \
-e RABBITMQ_MANAGEMENT_QUEUES_queue2='{"name":"queue2","vhost":"/vhost2","durable":true,"auto_delete":false,"arguments":{"x-dead-letter-exchange":"queue2-retry-requeue","x-message-ttl":300000}}' \
-e RABBITMQ_MANAGEMENT_EXCHANGES_exchange1='{"name":"exchange1","vhost":"vhost1","type":"topic","durable":true,"auto_delete":false,"internal":false,"arguments":{}}' \
-e RABBITMQ_MANAGEMENT_EXCHANGES_exchange2='{"name":"exchange2","vhost":"vhost2","type":"topic","durable":true,"auto_delete":false,"internal":false,"arguments":{}}' \
-it --name rabbitmq <registry>/rabbitmq --entrypoint bash
Which gives us rabbitmq setup so,
root@a08a2445d8e6:/# rabbitmqctl list_users
Listing users ...
guest [administrator]
user1 [administrator]
user2 [administrator]
root@a08a2445d8e6:/# rabbitmqctl list_vhosts
Listing vhosts ...
/
/vhost1
/vhost2
root@a08a2445d8e6:/# rabbitmqctl list_policies -p /vhost1
Listing policies ...
/vhost1 undefined all test1 {"dead-letter-exchange":"exchange1","ha-mode":"all"} 0
root@a08a2445d8e6:/# rabbitmqctl list_queues -p /vhost2
Listing queues ...
queue2 0
root@a08a2445d8e6:/# rabbitmqctl list_permissions -p /vhost1
Listing permissions in vhost "/vhost1" ...
user1 .* .* .*
root@63d2c3457ff2:/# rabbitmqctl list_exchanges -p /vhost1
Listing exchanges ...
[...]
exchange1 topic
root@63d2c3457ff2:/# rabbitmqctl list_exchanges -p /vhost2
Listing exchanges ...
[...]
exchange2 topic