Skip to content

Latest commit

 

History

History
65 lines (60 loc) · 2.6 KB

docker-mod-cluster.adoc

File metadata and controls

65 lines (60 loc) · 2.6 KB

Java EE Application on Mod Cluster

A frequent requirement for Java EE based applications is running them on a cluster of application server. While setup and test can be complicated on developer machines, this is where Docker can play to it’s full potential. With the help of images and automatic port mapping, we’re ready to test Ticket Monster on a couple of WildFly instances and add and remove them randomly.

The diagram below shows what will be achieved in this section:

wildfly cluster1
Figure 1. Standalone Cluster with WildFly and mod_cluster
  1. Start Apache HTTPD server

    docker run -d --name modcluster -p 80:80 classroom.example.com:5000/mod_cluster
  2. Open http://dockerhost/mod_cluster_manager in your browser to see the empty console as:

    wildfly cluster2
    Figure 2. Apache HTTPD runing mod_cluster_manager interface
  3. Start Postgres database container, if not already running:

    docker run --name db -d -p 5432:5432 -e POSTGRES_USER=ticketmonster -e POSTGRES_PASSWORD=ticketmonster-docker classroom.example.com:5000/postgres
  4. Start the first WildFly instance:

    docker run -d --name server1 --link db:db --link modcluster:modcluster classroom.example.com:5000/ticketmonster-pgsql-wildfly

    Besides linking the database container using --link db:db, we also link the ``modcluster'' container. This should be done rather quickly and if you now revisit the mod_cluster_manager in your browser, then you can see that the first server was registered with the loadbalancer:

    wildfly cluster3
    Figure 3. First WildFly instance registered with Load Balancer
  5. To make sure the Ticket Monster application is also running just visit http://dockerhost/ticket-monster and you will be presented with the Ticket Monster welcome screen.

    wildfly cluster4
    Figure 4. Clustered Ticket Monster Application
  6. Start as many WildFly instances as you want (and your computer memory can handle):

    docker run -d --name server2 --link db:db --link modcluster:modcluster classroom.example.com:5000/ticketmonster-pgsql-wildfly
    docker run -d --name server3 --link db:db --link modcluster:modcluster classroom.example.com:5000/ticketmonster-pgsql-wildfly
    docker run -d --name server4 --link db:db --link modcluster:modcluster classroom.example.com:5000/ticketmonster-pgsql-wildfly
  7. Stop some servers:

    docker stop server1
    docker stop server3

    Ensure that the application is still accessible at http://dockerhost/ticket-monster.