Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article shows you how to deploy the Spring PetClinic sample application to Azure Container Apps using a Dockerfile.
There are several options available for deploying Java applications, including the following options:
- Deployment from a local file system or from a code repository.
- Deployment using Maven or an IDE.
- Deployment using a WAR file, a JAR file, or directly from source code.
By the end of this tutorial, you deploy a web application that you can manage through the Azure portal. The following screenshot shows the home page of the PetClinic application deployed to Azure Container Apps:
- An Azure subscription. Create one for free..
- The
Contributor
orOwner
permission on the Azure subscription. For more information, see Assign Azure roles using the Azure portal. - A GitHub account.
- Git
- Azure CLI
- The Azure Container Apps CLI extension, version 0.3.47 or higher. Use the following command to install the latest version:
az extension add --name containerapp --upgrade --allow-preview
- The Java Development Kit, version 17 or later.
- Apache Maven
Build the Spring PetClinic application on your local machine by using the following steps:
Clone the Azure Container Apps Java Samples repo by using the following command:
git clone https://github.com/Azure-Samples/azure-container-apps-java-samples.git
Navigate to the spring-petclinic folder by using the following command:
cd azure-container-apps-java-samples/spring-petclinic/spring-petclinic/
Initialize and update the PetClinic application to the latest version by using the following command:
git submodule update --init --recursive
Build the PetClinic application by using the following command:
./mvnw clean install
Run your application locally by using the following command:
./mvnw spring-boot:run
After the application is up, access it locally at
http://localhost:8080
.
Deploy the PetClinic application to Azure Container Apps by using the following steps:
Set the necessary environment variables by using the following commands:
export RESOURCE_GROUP="pet-clinic-container-apps" export LOCATION="canadacentral" export ENVIRONMENT="env-pet-clinic-container-apps" export CONTAINER_APP_NAME="pet-clinic"
Sign in to Azure from the CLI if you aren't already signed in. For more information, see the Setup section of Build and deploy from local source code to Azure Container Apps.
Build and deploy the Spring PetClinic app by using the following command. The
..
(dot dot) indicates that you're using the Dockerfile in the parent folder.az containerapp up \ --resource-group $RESOURCE_GROUP \ --name $CONTAINER_APP_NAME \ --location $LOCATION \ --environment $ENVIRONMENT \ --source ..
This command accomplishes the following tasks:
- Creates the resource group.
- Creates an Azure container registry.
- Builds the container image and pushes it to the registry.
- Creates the Container Apps environment with a Log Analytics workspace.
- Creates and deploys the container app using the built container image.
After the deployment finishes, go to the Azure portal Overview page of your container app and select Application Url to see the application running in the cloud.
If you plan to continue working with more quickstarts and tutorials, you might want to leave these resources in place. When you no longer need the resources, you can remove them to avoid Azure charges, by using the following command:
az group delete --name $RESOURCE_GROUP