Deploy Aspire to Azure Container Apps using the Aspire CLI
When you deploy Aspire applications to Azure Container Apps using the aspire deploy command, the platform provides several deployment options and configurations. This guide explains how to use the Aspire CLI to deploy your applications to Azure Container Apps with various configuration options.
Prerequisites
Section titled “Prerequisites”- Aspire common prerequisites
- The Aspire CLI installed
- An Azure subscription: Create one for free
- Install the Azure CLI
Enable the deploy command
Section titled “Enable the deploy command”The aspire deploy command is currently in preview and must be explicitly enabled. Enable the feature by setting the following environment variable:
export DOTNET_ASPIRE_ENABLE_DEPLOY_COMMAND=true$env:DOTNET_ASPIRE_ENABLE_DEPLOY_COMMAND="true"Authenticate with Azure
Section titled “Authenticate with Azure”Before deploying your application, authenticate with Azure using the Azure CLI:
az loginThis command opens a browser window for you to sign in to your Azure account. After authentication completes, you can proceed with deployment.
Create an Aspire project
Section titled “Create an Aspire project”If you don’t already have an Aspire project, create one using the Aspire CLI:
aspire new AspireAppcd AspireAppThis creates a new solution with an AppHost project and a sample web frontend.
Deploy using aspire deploy
Section titled “Deploy using aspire deploy”Deploy your application to Azure Container Apps using the aspire deploy command:
aspire deployThe command performs the following steps:
-
Validates your configuration: Checks for required settings and dependencies.
-
Generates the deployment manifest: Creates a manifest describing all resources in your application.
-
Provisions Azure resources: Creates or updates Azure Container Apps, Container Registry, and other required resources.
-
Builds and pushes container images: Builds Docker images for your projects and pushes them to Azure Container Registry.
-
Deploys the application: Updates your Container Apps with the new images and configuration.
Specify deployment parameters
Section titled “Specify deployment parameters”You can provide deployment parameters inline using the --deployment-param flag:
aspire deploy --deployment-param location=eastus --deployment-param environment=productionUse a parameters file
Section titled “Use a parameters file”For complex deployments, create a parameters file:
{ "location": "eastus", "environment": "production", "resourceGroupName": "my-aspire-app-rg"}Then reference the file during deployment:
aspire deploy --deployment-params-file deployment-params.jsonDeployment process
Section titled “Deployment process”During deployment, the CLI displays progress information:
Building projects... ✓ AspireApp.Web ✓ AspireApp.ApiService
Pushing images to registry... ✓ aspireapp-web:latest ✓ aspireapp-apiservice:latest
Provisioning Azure resources... ✓ Resource group: aspireapp-rg ✓ Container Registry: aspireappacr ✓ Container Apps Environment: aspireapp-env ✓ Container App: web ✓ Container App: apiservice
Deployment complete!Web endpoint: https://web.proudriver-12345678.eastus.azurecontainerapps.ioMonitor your deployment
Section titled “Monitor your deployment”After deployment completes, monitor your application using several methods:
View logs using Azure CLI
Section titled “View logs using Azure CLI”az containerapp logs show --name web --resource-group aspireapp-rg --followAccess the Azure portal
Section titled “Access the Azure portal”Navigate to the Azure portal to:
- View application metrics and logs
- Configure scaling rules
- Manage environment variables and secrets
- Monitor application health
Use Application Insights
Section titled “Use Application Insights”For comprehensive monitoring, integrate Application Insights:
var builder = DistributedApplication.CreateBuilder(args);
var appInsights = builder.AddAzureApplicationInsights("monitoring");
builder.AddProject<Projects.AspireApp_Web>("web") .WithReference(appInsights);
builder.AddProject<Projects.AspireApp_ApiService>("apiservice") .WithReference(appInsights);
builder.Build().Run();Troubleshooting
Section titled “Troubleshooting”Authentication issues
Section titled “Authentication issues”If you encounter authentication errors:
-
Verify you’re logged in to Azure:
Check Azure login status az account show -
Ensure you have the correct subscription selected:
Set Azure subscription az account set --subscription <subscription-id> -
Verify your account has the necessary permissions to create resources in the target resource group.
Image build failures
Section titled “Image build failures”If container image builds fail:
- Ensure Docker Desktop or Podman is running
- Check that your Dockerfile syntax is correct
- Verify you have sufficient disk space for image builds
Deployment failures
Section titled “Deployment failures”If the deployment fails:
- Check the error message for specific details
- Verify your deployment parameters are correct
- Ensure the target region supports Azure Container Apps
- Check Azure service health for any outages
Clean up resources
Section titled “Clean up resources”To remove all deployed resources:
az group delete --name aspireapp-rg --yes --no-wait