Azure Made Simple: Containerizing and Hosting Java Apps on RHEL VMs

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"]

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
1. Open a terminal and navigate to your Dockerfile Directory.

2. Build 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.

Step 3: Push the image into Azure Container Registry 

1. Log into Azure

az login
2. Log into ACR

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
1. SSH into VM:
ssh <your-username>@<your-vm-ip-address>
2. Install Docker:
sudo yum install -y docker
sudo systemctl start docker
sudo systemctl enable docker
3. Log into ACr from the VM: Enter your ACR credentials when promoted.
docker login <your-acr-name>.azurecr.io

Step 5: Deploy the container on RHEL
1. Pull the image:
docker pull <your-acr-name>.azurecr.io/your-app-image:latest
2. Run the container:
docker run -d -p 8080:8080 <your-acr-name>.azurecr.io/your-app-image:latest

Step 6: Test the deployment
1. Access your application in a browser at:
http://<your-vm-ip>:8080
Ensure the application runs as expected.

Best Practices:
  • Secure ACR Access: Use Azure-managed identities or service principals for secure authentication.
  • Monitor the VM: Leverage Azure Monitor for performance tracking.
  • Keep Docker Updated: Regularly update Docker for enhanced security and reliability

  • 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.

    Leave a Comment

    Your email address will not be published. Required fields are marked *

    Scroll to Top