FROM rabbitmq:management-alpineCOPY .erlang.cookie /usr/var/lib/rabbitmq/.erlang.cookieCOPY cluster-entrypoint.sh /usr/local/bin/cluster-entrypoint.shCOPY src/rabbitmq/plugins /plugins/RUN set -eux; \ rabbitmq-plugins enable --offline rabbitmq_management rabbitmq_message_deduplication; \ rm -f /etc/rabbitmq/conf.d/20-management_agent.disable_metrics_collector.conf; \ cp /plugins/rabbitmq_management-*/priv/www/cli/rabbitmqadmin /usr/local/bin/rabbitmqadmin; \ [ -s /usr/local/bin/rabbitmqadmin ]; \ chmod +x /usr/local/bin/rabbitmqadmin; \ apk add --no-cache python3; \ rabbitmqadmin --versionENV JOIN_CLUSTER_HOST=rabbitmq-cluster1@railwayENV RABBITMQ_NODENAME=rabbitmq-cluster2RUN chmod 755 /usr/local/bin/cluster-entrypoint.shENTRYPOINT ["/usr/local/bin/cluster-entrypoint.sh"]CMD ["rabbitmq-server"]
#!/bin/bashset -e# Change .erlang.cookie permissionchmod 400 /usr/var/lib/rabbitmq/.erlang.cookie# Use the FQDN provided by RailwayHOSTNAME=$(hostname -f)echo "Starting RabbitMQ Server for host: $HOSTNAME"if [ -z "$JOIN_CLUSTER_HOST" ]; then /usr/local/bin/docker-entrypoint.sh rabbitmq-server & sleep 30 rabbitmqctl wait --timeout 60000 /usr/var/lib/rabbitmq/mnesia/rabbit@$HOSTNAME.pidelse /usr/local/bin/docker-entrypoint.sh rabbitmq-server -detached sleep 30 rabbitmqctl wait --timeout 60000 /usr/var/lib/rabbitmq/mnesia/rabbit@$HOSTNAME.pid echo "Stopping RabbitMQ application on node $HOSTNAME..." rabbitmqctl stop_app echo "Joining node $HOSTNAME to cluster $JOIN_CLUSTER_HOST..." rabbitmqctl join_cluster $JOIN_CLUSTER_HOST if [ $? -ne 0 ]; then echo "Error joining cluster. Exiting." exit 1 fi echo "Starting RabbitMQ application on node $HOSTNAME..." rabbitmqctl start_appfi# Keep foreground process active ...tail -f /dev/null