Deploying a 3-Tier Application Using Docker
info
Been running my brain around in circles thinking about how to manage the Glassfish cluster. Derrr, in Glassfish cluster each server instance is assigned its own IP and Glassfish ensures that all server instances in the cluster are synchronised. It doesn't matter which server instance you communicate with, Glassfish ensures they are synced. NGINX can be used as load balancer via its reverse proxy configuration. So, I will set up an NGINX reverse proxy that distributes messages to each server instance as it sees fit. By doing so, Glassfish will ensure the other server instances are synced.
The Architecture
The architecture I have chosen is one being used on a grad programme.
Component | Deployment Region | Solution Technology |
---|---|---|
Web Server | docker container (A) | Glassfish 4.1.2 |
Application Server | docker container (A) | Glassfish 4.1.2 |
Database Server | docker container (B) | MySQL 5.7.17 |
So essentially I have installed the web server and application server components on a single glassfish server that is running in a single docker container (A). The database server has been deployed in its own docker container (B).
See the sidebar sections on how to configure each container for Glassfish and MySQL.
Once the containers are setup, you may need to shell into the glassfish container if the domain is not running. See http://docs.oracle.com/javaee/6/tutorial/doc/bnadi.html.
To deploy a war file, use docker cp and copy the war file to /opt/glassfish4glassfish/domains/domain2/autodeploy/ - glassfish will unarchive the file and load it into the application server.
Important
Glassfish disable autdeploy once a cluster has been activated, so you have to manually un-archive the war files into each application folder in the server instances within the cluster
Obtaining container images
The container images can be found at docker hub
Component | Docker hub Repository | User and Password info |
---|---|---|
Web Application | https://hub.docker.com/r/stream2stream/glassfish-4.1.2-with-app/ | Glassfish asadmin - no password domain2 - user=admin, password=ppp |
Business Application | https://hub.docker.com/r/stream2stream/glassfish-4.1.2-with-app/ | Glassfish asadmin - no password domain2 - user=admin, password=ppp |
Database | https://hub.docker.com/r/stream2stream/glassfish-4.1.2-with-app/ | user=selvyn, password=dbGradProg2017@M5673 |
Bootstrapping the containers
Run the glassfish container using the following command
docker run -p <local port 1>:4848 -p <local port 2>:8080 -p <local port 3>:8181 -dit <image id>
Better still
use this docker-run-glassfish.bat to run the image. We've configured glassfish so the servers run in a cluster on a single node, so it one goes down, there should still be enough availability
NOTE: <local port 1, 2, and 3 should all be different
NOTE: it is important that you specify the -dit switch
You will need to perform some manual actions in order to ensure that the Glassfish container is fully functional.
- Shell into the container using the following command
- docker exec -it <image id> bash
- Once in the container run the following commands
- cd ~
- source .profile
- asadmin
- start-domain domain2
It will take about 1 minute (or sometimes less) before the container's functionality is fully enabled
Obtaining docker-machine IP address
Execute the following command
docker-machine inspect
Scan through the output and look for
"Driver": {
"IPAddress": "<some IP address>",
This is the IP address of all the containers on this local host
Viewing server status and applications in browser
info
See bootstrapping containers above for information on <local port #>
<application name> is usually a war file name that has been deployed to a JSP2 container
To view the server status, in your browser enter the following URL
<some IP address>:<local port 1>
When the admin login appears, enter
username = admin
password = ppp
To view an application enter the following URL
<some IP address>:<local port 2>/<application name>