0% found this document useful (0 votes)
14 views8 pages

Containerization_of_Java_Project_using_Docker

Java using docker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

Containerization_of_Java_Project_using_Docker

Java using docker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Containerization of Java Project using

Docker
🔗 GitHub Repository:
https://github.com/KodimurthiHarish/vprofile-project.git

🎯 Project Objective
The goal of this project is to containerize a full-stack Java-based application (vProfile) using
Docker and Docker Compose. The application consists of several services:

* Java Web Application (Spring Boot WAR deployed on Tomcat)


* MySQL Database
* NGINX for frontend reverse proxy
* Memcached for caching
* RabbitMQ for messaging

Hosting Environment
1. Platform :Oracle virtual Box
2. Docker Engine : Installed using apt
3. Docker Compose: Installed via plugin
4. Version Control : Git
5. Editor : Visual Studio Code

⚙️ Tools & Technologies

Tool/Technology Purpose
GitHub Version control
Docker Containerization
Docker Compose Service orchestration
MySQL Relational Database
Memcached Caching layer
RabbitMQ Message Broker
NGINX Reverse Proxy
Apache Tomcat Servlet container
Maven Java build automation
🗂️ Project Directory Structure

vprofile-project/
vagrant/
├── windowsAndMacIntel/ # For Windows & Intel-based Macs
├── Docker-files/ # All Docker-related files
│ ├── app/ # Java Spring Boot WAR app
│ │ └── Dockerfile
│ ├── db/ # MySQL service setup
│ │ ├── Dockerfile
│ │ └── db_backup.sql
│ └── web/ # NGINX reverse proxy
│ ├── Dockerfile
│ └── nginvproapp.conf
├── Vagrantfile # For spinning up VMs via Vagrant
└── compose.yaml # Docker Compose to run all services Dockerfiles
Explanation

📦 App (Java Spring Boot WAR on Tomcat)

Purpose:

To clone, build, and package a Java Spring Boot application into a .war file and deploy it
using Tomcat.

FROM maven:3.9.9-eclipse-temurin-21-jammy AS BUILD_IMAGE

• Base image with Maven and Java 21 installed.


• Used for building the Java project.
RUN git clone https://github.com/KodimurthiHarish/vprofile-project.git
RUN cd vprofile-project && git checkout containers && mvn install

• Clones your GitHub repo.


• Checks out the containers branch.
• Runs mvn install to compile the app and generate the WAR file.
FROM tomcat:10-jdk21

• Runtime image based on Apache Tomcat 10 with Java 21.

LABEL "Project"="Vprofile"
LABEL "Author"="Harish"
RUN rm -rf /usr/local/tomcat/webapps/*

• Deletes default Tomcat web apps to avoid conflicts.


COPY --from=BUILD_IMAGE vprofile-project/target/vprofile-v2.war
/usr/local/tomcat/webapps/ROOT.war
• Copies the WAR file built earlier into Tomcat’s ROOT directory for deployment.

EXPOSE 8080
CMD ["catalina.sh", "run"]

• Exposes port 8080.


• Starts the Tomcat server.

📦 DB (MySQL)
Purpose:

To run a MySQL database container with pre-configured credentials and load initial data.

FROM mysql:8.0.33

• Uses official MySQL 8 image.

LABEL "Project"="Vprofile"
LABEL "Author"="Harish"

ENV MYSQL_ROOT_PASSWORD="vprodbpass"
ENV MYSQL_DATABASE="accounts"

• Sets root password and default database.


ADD db_backup.sql docker-entrypoint-initdb.d/db_backup.sql

• Loads db_backup.sql during the container startup.


• Docker automatically runs scripts in this folder on first container creation.

📦 Web (NGINX)
Purpose:

• To serve as a frontend reverse proxy using NGINX.


FROM nginx

• Uses official NGINX image.

LABEL "Project"="Vprofile"
LABEL "Author"="Harish"

RUN rm -rf /etc/nginx/conf.d/default.conf


COPY nginvproapp.conf /etc/nginx/conf.d/vproapp.conf

• Replaces the default NGINX config with a custom one tailored for the app.
🧩 Docker Compose File (compose.yaml)

Purpose:

To define and run multi-container Docker applications with a single command.

📦 vprodb (MySQL)
services:
vprodb:
build:
context: ./Docker-files/db

• Builds MySQL image using custom Dockerfile.


image: harishkodimurthi/vprofiledb
container_name: vprodb
ports:
- "3036:3036"
volumes:
- vprodbdata:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=vprodbpass

• Sets container name, port, and volume for data persistence.


• Passes MySQL environment variables.

📦 vprocache01 (Memcached)
vprocache01:
image: memcached
container_name: vprocache01
ports:
- "11211:11211"

• Runs Memcached, used for caching application data.

📦 vpromq01 (RabbitMQ)
vpromq01:
image: rabbitmq
container_name: vpromq01
ports:
- "5672:5672"
environment:
- RABBITMQ_DEFAULT_USER=guest
- RABBITMQ_DEFAULT_PASS=guest

• Runs RabbitMQ, a message broker used for async communication.


📦 vproapp (Java App)
vproapp:
build:
context: ./Docker-files/app
image: harishkodimurthi/vprofileapp
container_name: vproapp
ports:
- "8080:8080"
volumes:
- vproappdata:/usr/local/tomcat/webapps

• Builds the Java app using the app Dockerfile.


• Deploys the .war to Tomcat and runs it.
• Port 8080 is used to access the app.

📦 vproweb (NGINX)
vproweb:
build:
context: ./Docker-files/web
image: harishkodimurthi/vprofileweb
container_name: vproweb
ports:
- "80:80"

• Builds the NGINX reverse proxy.


• Serves frontend traffic on HTTP port 80.

🔄 Volumes
volumes:
vprodbdata: {}
vproappdata: {}

• Ensures data persistence even after container restarts or deletion.


• vprodbdata: For MySQL
• vproappdata: For Tomcat app deployment

🚀 Docker Installation & Commands

sudo apt-get update


sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o
/etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc]


https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update


sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y

usermod -aG docker vagrant

🧪 Build & Run Instructions

# Clone the repo


git clone https://github.com/KodimurthiHarish/vprofile-project.git
cd vprofile-project

# Build all images


docker compose build

# Run all services


docker compose up -d

# View running containers


docker ps

Push Images to Docker


docker login
docker push harishkodimurthi/vprofileapp
docker push harishkodimurthi/vprofiledb
docker push harishkodimurthi/vprofileweb

✅ Output Validation
🏁 Conclusion

This project demonstrates containerization of a multi-tier Java-based application using


Docker and Docker Compose. It showcases:

WAR packaging and deployment on Tomcat


Database and schema initialization using MySQL
Memcached and RabbitMQ setup
Reverse proxy with NGINX
Complete orchestration via Docker Compose

You might also like