Introduction
Deploying Java applications efficiently is crucial for modern cloud-based environments. This guide walks you through deploying a JAR/WAR file to a Red Hat Enterprise Linux (RHEL) Virtual Machine (VM) in Azure, utilizing Azure Container Registry (ACR). This process is particularly well-suited for lift-and-shift applications, allowing you to migrate existing workloads to the cloud with minimal changes. Learn how to set up, configure, and deploy your application with ease.
Prerequisites
Ensure you have the following ready:
- Azure Account: Active Azure subscription.
- RHEL Virtual Machine: Provisioned RHEL VM in Azure.
- Azure CLI: Installed and authenticated.
- Docker: Installed on your local machine.
- Java Runtime Environment: Installed on the RHEL VM.
- JAR/WAR File: Your application prepared for deployment.
- Azure Container Registry (ACR): Set up in Azure.
Step 1: Prepare the Application
Begin by ensuring your application file is deployment-ready. Then, create a Dockerfile for containerizing your application.
Example Dockerfile for JAR:
FROM openjdk:17-jdk-alpine
WORKDIR /app
COPY your-application.jar /app/your-application.jar
CMD ["java", "-jar", "/app/your-application.jar"]
WORKDIR /app
COPY your-application.jar /app/your-application.jar
CMD ["java", "-jar", "/app/your-application.jar"]
Example Dockerfile for WAR:
FROM tomcat:10.1-jdk17
WORKDIR /usr/local/tomcat/webapps/
COPY your-application.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD ["catalina.sh", "run"]
Step 2: Build and Test the Docker Image
docker build -t your-app-image:latest
3. Test the image locally.
docker run -p 8080:8080 your-app-image:latest
4. Access the application locally:
- For WAR files:
http://localhost:8080 - For JAR files: Use the appropriate endpoint.
az login
az acr login --name <your-acr-name>
3. Tag the image.
docker tag your-app-image:latest <your-acr-name>.azurecr.io/your-app-image:latest
4. Push the image to ACR:
docker push <your-acr-name>.azurecr.io/your-app-image:latest
Step 4: Configure the RHEL VM
ssh <your-username>@<your-vm-ip-address>
sudo yum install -y docker sudo systemctl start docker sudo systemctl enable docker
docker login <your-acr-name>.azurecr.io
Step 5: Deploy the container on RHEL
docker pull <your-acr-name>.azurecr.io/your-app-image:latest
docker run -d -p 8080:8080 <your-acr-name>.azurecr.io/your-app-image:latest
Step 6: Test the deployment
http://<your-vm-ip>:8080
Conclusion:
This guide provides a comprehensive approach to deploying JAR/WAR files to a RHEL VM in Azure using Azure Container Registry. By containerizing your application and leveraging Azure’s ecosystem, you can ensure a seamless and secure deployment process.


