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:
-
Start Apache HTTPD server
docker run -d --name modcluster -p 80:80 classroom.example.com:5000/mod_cluster
-
Open http://dockerhost/mod_cluster_manager in your browser to see the empty console as:
-
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
-
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: -
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.
-
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
-
Stop some servers:
docker stop server1 docker stop server3
Ensure that the application is still accessible at http://dockerhost/ticket-monster.