This repository will detail steps to containerize Java application running on WildFly application server and running them in Azure App Service and Azure Container Apps.
In this tutorial, WildFly 10.1.0 version is being used. However, any version that is downloadable from WildFly site can be used. If you are changing the version, you may have to change the download URL in the WildFly-Base/Dockerfile.
All commands are run in a bash shell for this tutorial.
These steps below assume the following:
-
Azure Subscription is setup.
-
Docker is setup and verify by running the command below.
docker --version
-
Clone this repository by running the commands below.
git clone https://github.com/fsaleemm/JavaWildFlyContainers.git cd JavaWildFlyContainers
cd WildFly-Base
docker build -t wildfly-base .
docker run -p 8080:8080 wildfly-base
Launch browser and navigate to http://localhost:8080. You should get the below screen.
Stop the container by typing Ctrl+c.
The Petstore application source code is in this repository.
To build the application package use maven.
git clone https://github.com/agoncal/agoncal-application-petstore-ee7.git
cd agoncal-application-petstore-ee7
mvn clean install -DskipTests
Copy the "war" file in the agoncal-application-petstore-ee7/target directory to WildFly-App directory.
Alternatively, you can use the applicationPetstore.war already in the WildFly-App directory.
cd ../WildFly-App
docker build -t <Your-Azure-Container-Registry-Name>.azurecr.io/wildfly-app .
docker run -p 8080:8080 <Your-Azure-Container-Registry-Name>.azurecr.io/wildfly-app
Launch browser and navigate to http://localhost:8080/applicationPetstore/. You should see the application screen below.
Stop the container by typing Ctrl+c.
Login to your Azure Container Registry
az acr login -n <Your-Azure-Container-Registry-Name>
Publish the docker image to your registry
docker push <Your-Azure-Container-Registry-Name>.azurecr.io/wildfly-app
az login
RESOURCE_GROUP="<Your-Resource-Group>"
LOCATION="<Your-preferred-location>"
az group create --name $RESOURCE_GROUP --location $LOCATION
Create App, set the configuration setting, enable managed identity, give managed identity access to ACR, and deploy image from ACR.
ASP_NAME="<Your-App-Service-Plan-Name>"
APP_NAME="<Your-App-Name>"
REGISTRY_NAME="<Your-Azure-Container-Registry-Name>"
ACR_RESOURCE_GROUP="<Resource Group for Azure Container Registry>" # Allowing for ACR in different RG
# Create App Service Plan
az appservice plan create --name $ASP_NAME --resource-group $RESOURCE_GROUP --is-linux
# Create App
az webapp create --resource-group $RESOURCE_GROUP --plan $ASP_NAME --name $APP_NAME --deployment-container-image-name <Your-Azure-Container-Registry-Name>.azurecr.io/wildfly-app:latest
# Set port as container exposes port 8080. The App Service request port will always be 443 (https)
az webapp config appsettings set --resource-group $RESOURCE_GROUP --name $APP_NAME --settings WEBSITES_PORT=8080
# Enable Managed Identity on App Service
APP_SERVICE_PRINCIPAL=$(az webapp identity assign --resource-group $RESOURCE_GROUP --name $APP_NAME --query principalId --output tsv)
# Get subscription Id
SUBSCRIPTION_ID=$(az account show --query id --output tsv)
# Assign AcrPull role for App Service on Container Registry
az role assignment create --assignee $APP_SERVICE_PRINCIPAL --scope /subscriptions/$SUBSCRIPTION_ID/resourceGroups/$ACR_RESOURCE_GROUP/providers/Microsoft.ContainerRegistry/registries/$REGISTRY_NAME --role "AcrPull"
# Set App Service to use Managed Identity for ACR
az resource update --ids /subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RESOURCE_GROUP/providers/Microsoft.Web/sites/$APP_NAME/config/web --set properties.acrUseManagedIdentityCreds=True
Launch browser and navigate to https://<Your-App-Name>.azurewebsites.net/applicationPetstore. You should see the application below:
NOTE: The steps below are based on the preview version of Azure Container Apps. The steps may change for the GA version.
In preview version, there is no ACR integration using Managed Identities, so ACR needs to have Admin user enabled.
-
Run through these Setup steps.
-
Run through these Create an environment steps.
-
Create Container App following below steps:
RESOURCE_GROUP="<Your-Resource-Group>" CONTAINERAPPS_ENVIRONMENT="<Your-Container-Apps-Environment-Name>" CONTAINERAPPS_Name="<Your-Container-Apps-Name>" CONTAINER_IMAGE_NAME="<Your-Azure-Container-Registry-Name>.azurecr.io/wildfly-app:latest" REGISTRY_LOGIN_SERVER="<Your-Azure-Container-Registry-Name>.azurecr.io" REGISTRY_USERNAME="<Your-ACR-Username>" REGISTRY_PASSWORD="<Your-ACR-Password>" # Create the Container App az containerapp create \ --name $CONTAINERAPPS_Name \ --resource-group $RESOURCE_GROUP \ --environment $CONTAINERAPPS_ENVIRONMENT \ --image $CONTAINER_IMAGE_NAME \ --registry-login-server $REGISTRY_LOGIN_SERVER \ --registry-username $REGISTRY_USERNAME \ --registry-password $REGISTRY_PASSWORD \ --target-port 8080 \ --ingress 'external' \ --query configuration.ingress.fqdn
The output of the create container app command will provide the URL of the application.
Launch browser and navigate to https://<URL-FROM-CREATE-CONTAINER-APP-OUTPUT>/applicationPetstore. You should see the below screen:
Migrate custom software to Azure App Service using a custom container
Container Apps QuickStart: Deploy an existing container image with the Azure CLI
Run a custom container in Azure App Service
Application - Petstore Source Code
Azure-Samples - app-service-wildfly
This is an example intended for illustration purposes and is not production ready code.