Exercise - Deploy Spring Boot application
This section guides you through deploying a Spring Boot application to Azure Container Apps. We cover packaging the application, setting up the Azure environment, and pushing the application to Azure Container Apps.
Setup
To sign in to the latest version of the Azure CLI, use the following steps, and follow the prompts to complete the authentication process:
Use the following command to sign in to the Azure CLI:
az login
Use the following upgrade command to ensure you're running the latest version of the Azure CLI:
az upgrade
Next, install or update the Azure Container Apps extension for the CLI, and register the Microsoft.App
and Microsoft.OperationalInsights
namespaces by using the following steps:
Important
If you receive errors about missing parameters when you run az containerapp
commands in the Azure CLI, be sure you have the latest version of the Azure Container Apps extension installed.
First, install or update the Azure Container Apps extension by using the following command or commands:
az extension add --name containerapp --upgrade
Register the
Microsoft.App
andMicrosoft.OperationalInsights
namespaces by using the following commands:az provider register --namespace Microsoft.App az provider register --namespace Microsoft.OperationalInsights
Create environment variables
Define the environment variables needed throughout this article by using the following commands:
export RESOURCE_GROUP="petclinic-containerapps"
export LOCATION="canadacentral"
export ENVIRONMENT="env-petclinic-containerapps"
export APP_NAME="petclinic"
Locate the sample code
Navigate to the azure-container-apps-java-samples/spring-petclinic/spring-petclinic directory of the project.
Build and deploy the container app
Build and deploy your first Spring Boot app with the containerapp up
command, which 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.
The containerapp up
command uses the Dockerfile in the root of the repository to build the container image. Use the following command to build the container image. The ..
(dot dot) tells the containerapp up
command to run the Dockerfile in the parent folder.
az containerapp up \
--resource-group $RESOURCE_GROUP\
--name $APP_NAME \
--location $LOCATION \
--environment $ENVIRONMENT \
--source ..
Verify deployment
After your deployment is complete, you should see the following success message with the project endpoint printed in the console. You can open the URL to verify that your project deployed to Azure.
Run ID: cxl was successful after 3m30s
Creating Containerapp petclinic in resource group petclinic-containerapps
Container app created. Access your app at https://petclinic.wonderful
Your container app petclinic has been created and deployed! Congrats!
Browse to your container app at: http://petclinic.wonderful
Stream logs for your container with: az containerapp logs show -n petclinic -g petclinic-containerapps
See full output using: az containerapp show -n petclinic -g petclinic-containerapps