Azure Container Instances allow you to rapidly deploy containers to the Microsoft Azure cloud without having to manage virtual machines and the corresponding infrastructure. Container Instances can be used to rapidly deploy Java EE and MicroProfile applications using Payara Micro as the underlying platform for your Cloud Native applications.
In this blog we will walk through deploying a MicroProfile RESTful webservice as a container. Payara Micro supports a full range of APIs and applications ranging from RESTful web services to full web applications that can be deployed on Container Instances.
Before we start we will create a resource group to contain the services we will create for this blog. Throughout the process, you will need to create names for resources that are different to the ones used in our examples.
Next, we will create a container registry within the same resource group. A container registry is needed to store our Docker images. Alternatively you can publish your image to docker hub or any other registry.
To use the registry from Docker we will need to login to the registry. To do so we need to know the credentials which can be found by running
this will show the username and pasword required for login via docker. note the URL for your container registry which will be shown when creating your registry.
docker login https://payaraaciregistry.azurecr.io
Creating the Base Docker Image
Instead of using the published Payara Micro Docker file for creating our application Docker image, we shall create our own. To do this I will assume you have a web application you wish to deploy and that you have downloaded Payara Micro from the Payara website.
To make things simpler for future applications, first we will create a base image for Payara Micro on Azure and then layer our application on top of the base image. By creating the base image in this manner, you can then reuse it for other applications and microservices while reducing the image sizes we push applications. We will create the base image from the Azul Zulu Open JDK image, as Payara support customers also get support for Azul Zulu Open JDK builds.
Our Dockerfile looks like this:
and can be built using:
Creating the Application Image
All we need to do now is layer the war file we wish to deploy onto this image.
I’ve created a simple war file demonstrating a simple MicroProfile JAX-RS web service in this repo, once you’ve cloned the repository build the application using maven and then build a local Docker image using the following command:
You can test this image using this command:
Once running you can test the REST service using the following URL: http://127.0.0.1:8080/AzureWebAppsExample/webresources/example
Pushing the Docker Image to the Azure Container Registry
Before we can use the created docker image with Azure App Services we need to upload the container to your Azure container registry. We can do this simply with Docker by tagging the local image as a remote image and then using Docker push:
You can test that your image has been uploaded successfully by using the Azure CLI:
Creating the ACI Container
Once our Docker image is available in the container registry we can create a new container instance:
Then, once the instance is created the fully qualified domain name of the instance should be shown in the output of the command, for example:
You should be able to access your application running on the domain name shown:
You can get the logs from your container:
Pass Configuration to your Application
If you hit the REST endpoint now you will see that the environment variable injected via the Config API is not configured. Environment variables can be set on creation using the --environment-variables flag. For example, to create the container passing in environment variables use the full command:
If you have followed along with this blog you will have deployed a MicroProfile RESTful webservice as a container to the Microsoft Azure cloud using Payara Micro. Learn more about Payara Micro, download the lightweight middleware platform, get Payara Micro Docker images, or watch demos on the website: https://www.payara.fish/payara_micro.