Horizontal scaling in docker

Hi guys, I’m using the docker-mendix-buildpack to get our app up and running on docker. I have a docker-compose file that start up my db, mendix and nginx load balancer. When only starting one instance of mendix it works 100%. The problem comes when using docker-compose up --scale service=5 to launch more than one instance of mendix. All instances of mendix wants to execute the database synchronization and the start up of all the mendix instances stop (db and load balancer starts up fine). This means mendix could not complete the database synchronization commands, so no schema is created. I have to go into pgAdmin and create the schema manually and use docker-compose start to restart the 5 failed mendix containers. “Magically” they all connect to the database and all 5 instances of mendix is up and running perfectly.   I’ve read all the documentation of docker-mendix-buildpack and also cf-mendix-buildpack. Don’t know if I’m missing something. I’ve tried  setting CF_INSTANCE_INDEX = 0 as an environment variable in my docker-compose file , but this gives all the containers  CF_INSTANCE_INDEX  = 0 and we’re back at square one again. Any help would be appreciated!   Thanks
3 answers

Easiest solution is to work with two container definitions. One with CF_INSTANCE_INDEX=0 and one with CF_INSTANCE_INDEX=1, the latter is the only one you scale… Example k8s implementation: https://github.com/MXClyde/mendix-kubernetes-azure/blob/master/manifests/kubernetes/kubernetes.yaml


Also interested in this!  Anyone?


I have this problem too.

The docker-mendix-buildpack source code shows that It will determines the master instance by some environment’s values if you are using k8s. But I can’t figure out how to generate a POD’s name to satisfy the regular expression.

def export_k8s_instance():
    logging.debug("Checking Kubernetes environment...")
    kubernetes_host = os.environ.get('KUBERNETES_SERVICE_HOST')
    if kubernetes_host is not None:
        hostname = os.environ.get('HOSTNAME')
        instance_match = re.search('(?<=-)[0-9]+$', hostname)
        if instance_match is not None:
            instance_number = instance_match.group(0)
            logging.info("Setting CF_INSTANCE_INDEX to {0} based on hostname {1}"
                .format(instance_number, hostname))
            os.environ['CF_INSTANCE_INDEX'] = instance_number