A wildfly cluster of 2 nodes running on Docker
Must have Docker (Community Edition will suffice) running.
Build war file to have something to deploy on wildfly:
mvn clean install
this application uses replicated HTTP session (<distributable></distributable>
tag in src/main/webapp/WEB-INF/web.xml).
Build a Docker image containig war running inside wildfly configured to run in clustered mode (-server-config=standalone-ha.xml
)
docker build -t wildfly-cluster-node .
Defining a Docker network specifing gateway and subnet is necessary to assign specific IPs to containers:
docker network ls
docker network create --driver bridge --gateway 172.19.0.1 --subnet 172.19.0.0/16 cluster_nw
docker network inspect cluster_nw
docker run --restart=always -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
The console is now available at:
http://localhost:9000/#/dashboard
Run 2 containers.
Note that specific IPs are only needed to configure a mod_jk balancer later.
docker run --network=cluster_nw --ip 172.19.0.2 -d -p 8081:8080 -p 9991:9990 --name wildfly-cluster-node-1 -t wildfly-cluster-node
docker run --network=cluster_nw --ip 172.19.0.3 -d -p 8082:8080 -p 9992:9990 --name wildfly-cluster-node-2 -t wildfly-cluster-node
http://localhost:8081/wildfly/helloworld
http://localhost:8082/wildfly/helloworld
docker container ls --all
docker exec -it 24d9244eb9f0 bash
docker container stop 8b64379c60e4
docker container rm 8b64379c60e4
go to src/mod_jk folder
docker build -t httpd-mod_jk .
then run
docker run --network=cluster_nw --ip 172.19.0.4 -d -p 80:80 --name mod_jk -t httpd-mod_jk
finally try url http://localhost/wildfly/helloworld for cluster
try url http://localhost:???/mcm for console
using https://hub.docker.com/r/karm/mod_cluster-master-dockerhub (GIT https://github.com/Karm/mod_cluster-dockerhub):
docker pull karm/mod_cluster-master-dockerhub
build mod_cluster:
cd ./src/mod_cluster
docker build -t mod_cluster_image .
build wildfly:
docker build -f Dockerfile-mod_cluster -t wildfly-mod_cluster-node .
start httpd with mod_cluster:
docker run -P -i -d --network=cluster_nw --ip 172.19.0.5 -p 80:80 --name mod_cluster mod_cluster_image
start wildfly:
docker run --network=cluster_nw --ip 172.19.0.6 -p 8086:8080 -p 9996:9990 --name wildfly-mod_cluster-node-1 -t wildfly-mod_cluster-node
docker run --network=cluster_nw --ip 172.19.0.7 -p 8087:8080 -p 9997:9990 --name wildfly-mod_cluster-node-2 -t wildfly-mod_cluster-node