Description
Section of replication is nasty:
Multi master replication
Quick example, with the default config.
#Create the first ldap server, save the container id in LDAP_CID and get its IP:
LDAP_CID=$(docker run --hostname ldap.example.org --env LDAP_REPLICATION=true --detach osixia/openldap:1.1.8)
LDAP_IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" $LDAP_CID)
#Create the second ldap server, save the container id in LDAP2_CID and get its IP:
LDAP2_CID=$(docker run --hostname ldap2.example.org --env LDAP_REPLICATION=true --detach osixia/openldap:1.1.8)
LDAP2_IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" $LDAP2_CID)
#Add the pair "ip hostname" to /etc/hosts on each containers,
#beacause ldap.example.org and ldap2.example.org are fake hostnames
docker exec $LDAP_CID bash -c "echo $LDAP2_IP ldap2.example.org >> /etc/hosts"
docker exec $LDAP2_CID bash -c "echo $LDAP_IP ldap.example.org >> /etc/hosts"
That's it!...
It is impossible to implement in production Compose file.
When I got to this, I'm going to work on it, but also ask your input and collaboration.
I think it can be done by algorithm:
Requirement - hostnames must be ldap.anything as main master, ldap[0-9].anything as other, as domain names.
Then we can do hostnames pattern match:
# This pattern match hostnames with dot, ldap.anything (master server)
echo "$HOSTNAME" | grep -E "^ldap\."
# Then search for ldap2.domain (if needed, ldap3... and so on)
# If lookup is successful - you found host. Do configuration with it (write results to /etc/hosts if it is a proper way)
# This pattern match hostnames with dot, ldap(numbers).anything
echo "$HOSTNAME" | grep -E "^ldap[0-9]+\."
# Then search for master ldap. (if needed, other numbers, ldap3... and so on)
# If lookup is successful - you found master host. Do configuration with it (write results to /etc/hosts if it is a proper way)
This is for any number of hosts, but we can make boundary for two-three.
This is simplicity way, if hostname is starting with ^ldap. - lookup ldap2 and write it, and otherwise. Which is the same I described above :p
Lookup retries/timeout is sufficient option, while next ldap(number) is not found - just stop further lookups.
This obviously part for initialization script, when replication set "true".
It is great to implement for two or three nodes - it is sufficient for majority of setups, I think. But I require your experienced input.