Skip to content

Deploying Martini Server Runtime within a cluster using Docker swarm mode

Docker swarm is a clustering tool for Docker containers. By deploying Martini Server Runtime in a Docker swarm cluster, you can efficiently manage multiple Docker instances. Docker swarm provides benefits such as ease of scaling, automatic recovery of failed instances, and network load balancing. Since Docker swarm is natively integrated with the Docker engine, setup is fast and easy, eliminating the need for a third-party application to manage your cluster.

Before proceeding, ensure you have knowledge of setting up a Docker swarm cluster and configuring a shared file system such as NFS.

Prerequisites

Before proceeding with the Docker swarm configuration, ensure you have the following prerequisites in place:

Considerations

Before proceeding, here are some important considerations:

  • Docker swarm does not guarantee that requests will be consistently served by the same server, which may affect applications relying on session stored within the application.
  • Martini Server Runtime requires a license for each virtual machine used in this setup.
  • Schedulers will be executed twice or equal to the number of Martini Server Runtime replicas distributed in all instances.
  • This setup will not work if you're using the embedded Hypersonic database, as it only allows one machine to use the database at a time.
  • In production, this setup must be configured with external applications such as Solr server, ActiveMQ, and databases.

Procedure

Follow these steps to deploy Martini Server Runtime within a Docker swarm cluster:

  1. Create Data Directories: Create the required data directories in the NFS server's /datastore directory to make all data files and directories available across all servers.

    1
    mkdir -p /datastore/apps/Martini-Runtime/{data,packages,logs,.java}
    
  2. Provision Martini as a Docker Service: Start a new Docker service using the following command. Ensure to customize the environment variables as needed. To override the Java maximum heap memory allocation pool (Xmx), pass a value to the environmental variable JAVA_XMX. Meanwhile, to override the Java initial memory allocation pool (Xms), pass the value to the variable JAVA_XMS.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    docker service create \
    -p :8080 \
    -p :8443 \
    --restart-condition on-failure --restart-max-attempts 5 \
    --env JAVA_XMS=${JVM_XMS_MEMORY}m --env JAVA_XMX=${JVM_XMX_MEMORY}m \
    --mount type=bind,source=/etc/localtime,destination=/etc/localtime,readonly \
    --mount type=bind,source=/datastore/apps/Martini-Runtime/data,destination=/data/data \
    --mount type=bind,source=/datastore/apps/Martini-Runtime/packages,destination=/data/packages \
    --mount type=bind,source=/datastore/apps/Martini-Runtime/logs,destination=/data/logs \
    --mount type=bind,source=${HOME}/.java,destination=/root/.java \
    --name martini \
    toroio/martini-runtime
    
  3. Verify Service: Ensure that the service has been created and replicated by running the following command:

    1
    docker service ls
    

    The replica column should indicate 1/1, meaning one task has been created for this service. You can get more details about your service by running:

    1
    docker service ps martini
    
  4. Scale Service: Scale the service to accommodate multiple tasks:

    1
    docker service scale martini=2
    

    This command will create an additional instance of Martini Server Runtime, automatically load balancing requests.

  5. Access Martini: Martini can be accessed using any of the Docker servers' IP addresses with the mapped port. Docker will automatically route requests to the server running Martini.

Upgrading to the Latest Version

To upgrade Martini Server Runtime to the latest version in a Docker swarm setup, follow these steps:

  1. Pull the new image from the Docker registry.
  2. Update all service tasks by executing:

    1
    docker service update --force martini
    

Upon execution, all nodes will automatically download the newest release from the Docker Hub and recreate all their tasks.

That's it! You've successfully deployed and upgraded Martini Server Runtime within a Docker swarm cluster.