In this post i will show Tomcat Clustering in Docker Container. In my previous post i discussed how to achieve tomcat clustering with Nginx Front end.

Its almost same scenario, but this time we will achieve via docker container.

Docker is an open-source project that automates the deployment of applications inside software containers, by providing an additional layer of abstraction and automation of operating-system-level virtualization on Linux.[4] Docker uses resource isolation features of theLinux kernel such as cgroups and kernel namespaces to allow independent "containers" to run within a single Linux instance, avoiding the overhead of starting and maintaining virtual machine  --Wikipedia

we need 4 docker container (3 tomcat containers + 1 Nginx container).
i used official tomcat and nginx images. official tomcat container not enable the cluster aware feature. so we will take official image and deploy our code and change the server.xml file and run the image as container.

we need to do some steps like deploy the our code and change server.xml file in all 3 tomcat container. so i used here docker-compose tool.

Docker Compose
Compose is a tool for defining and running multi-container applications with Docker. With Compose, you define a multi-container application in a single file, then spin your application up in a single command which does everything that needs to be done to get it running.

In docker compose we need to define in single file called yaml file.


In that file define all 3 tomcat container entries and change the server.xml file and tomcat-users.xml and deploy our app to ROOT location in tomcat.

check my github repo

Once we defined the yaml file then use single command like docker-compose up for start all 4 container up and running.
we can also use docker-compose -d up for run in background.

Screencast :