From ba4aab7443f7cb6862e84a91af21478022f28c4c Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 7 Nov 2022 21:59:16 +0100 Subject: [PATCH] Add Composer Examples section --- ecs/README.md | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/ecs/README.md b/ecs/README.md index 71d7de3..591e3c7 100644 --- a/ecs/README.md +++ b/ecs/README.md @@ -243,3 +243,120 @@ Build ejabberd Community Server base image for a given ejabberd version: ```bash ./build.sh 18.03 ``` + +# Composer Examples + +## Minimal Example + +This is the barely minimal file to get a usable ejabberd. +Store it as `docker-compose.yml`: + +```yaml +services: + main: + image: ejabberd/ecs + container_name: ejabberd + ports: + - "5222:5222" + - "5269:5269" + - "5280:5280" + - "5443:5443" +``` + +Create and start the container with the command: +```bash +docker-compose up +``` + +## Customized Example + +This example shows the usage of several customizations: +it uses a local configuration file, +stores the mnesia database in a local path, +registers an account when it's created, +and checks the number of registered accounts every time it's started. + +Download or copy the ejabberd configuration file: +```bash +wget https://raw.githubusercontent.com/processone/ejabberd/master/ejabberd.yml.example +mv ejabberd.yml.example ejabberd.yml +``` + +Create the database directory and allow the container access to it: +```bash +mkdir database +sudo chown 9000:9000 database +``` + +Now write this `docker-compose.yml` file: +```yaml +version: '3.7' + +services: + + main: + image: ejabberd/ecs + container_name: ejabberd + environment: + - CTL_ON_CREATE=register admin localhost asd + - CTL_ON_START=registered_users localhost ; + status + ports: + - "5222:5222" + - "5269:5269" + - "5280:5280" + - "5443:5443" + volumes: + - ./ejabberd.yml:/home/ejabberd/conf/ejabberd.yml:ro + - ./database:/home/ejabberd/database +``` + +## Clustering Example + +In this example, the main container is created first. +Once it is fully started and healthy, a second container is created, +and once ejabberd is started in it, it joins the first one. + +An account is registered in the first node when created, +and it should exist in the second node after join. + +Notice that in this example the main container does not have access +to the exterior; the replica exports the ports and can be accessed. + +```yaml +version: '3.7' + +services: + + main: + image: ejabberd/ecs + container_name: main + environment: + - ERLANG_NODE_ARG=ejabberd@main + - ERLANG_COOKIE=dummycookie123 + - CTL_ON_CREATE=register admin localhost asd + healthcheck: + test: netstat -nl | grep -q 5222 + start_period: 5s + interval: 5s + timeout: 5s + retries: 120 + + replica: + image: ejabberd/ecs + container_name: replica + depends_on: + main: + condition: service_healthy + ports: + - "5222:5222" + - "5269:5269" + - "5280:5280" + - "5443:5443" + environment: + - ERLANG_NODE_ARG=ejabberd@replica + - ERLANG_COOKIE=dummycookie123 + - CTL_ON_CREATE=join_cluster ejabberd@main + - CTL_ON_START=registered_users localhost ; + status +```