Container Apps - Deployments through UI and CLI
This post will cover a few different ways to use CLI / UI with Container Apps, in regards to deployment methods, as well as some general troubleshooting guidance for these methods.
Getting started
Azure Container Apps enables you to run microservices and containerized applications on a serverless platform. There is a few ways currently to deploy your applications to it, either from Bicep and ARM templates, GitHub Actions, Azure Portal, Azure CLI, Visual Studio, and Visual Studio Code.
Prerequesites:
- An Azure account with an active subscription. If you don’t have one, you can create one for free
- Existing container app. If it was not created ealier, you could create a Container App from portal.azure.com using “Quickstart image: Simple hello world container”
-
Install the Azure CLI, if you decide to use CLI instead of UI.
-
Once the environment and/or app is created, you may browse the Application URL from Container App -> Overview page to see if the app was created properly.
- Grab the Container App Name, Container Environment Name, Location, Resource Group and the Subscription ID from Container App -> Overview page
Deployment
Upload artifact from Portal UI
- Go to Container App -> Deployment -> Artifact (Preview)
- Browse .jar / .war / .zip / .tar.gz file from “Upload Artifact” section.
- If the upload is successful, you will see the succesful message in the top right corner.
- Browsing Application URL should show the output as expected. Sample output is below.
NOTE: I developed a RESTful API using Java Spring Boot. Hence it shows as a JSON array / string instead of a web page.
- If you still see the default parking page, check the logs from ContainerAppSystemLogs_CL. You may refer Port mismatch error for the complete details.
Upload artifact from CLI
- Run ‘az containerapp up’ with –artifact parameter pointing to the jar file
az containerapp up ` --name $API_NAME ` --resource-group $RESOURCE_GROUP ` --location $LOCATION ` --environment $ENVIRONMENT ` --artifact ./target/containerapps-albumapi-java-0.0.1-SNAPSHOT.jar ` --ingress external ` --target-port 8080 ` --subscription $SUBSCRIPTION
Sample logs from local machine.
This is the sample output
- To know more about other parameters, you may refer Deploy the Artifact.
Upload source code from CLI
- Run ‘az containerapp up’ with –source parameter pointing to the current directory
az containerapp up ` --name $API_NAME ` --resource-group $RESOURCE_GROUP ` --location $LOCATION ` --environment $ENVIRONMENT ` --source .
Sample logs from local machine.
This is the sample output
- To know more about other parameters, you may refer Deploy the Source Code
Troubleshooting
The TargetPort 80 does not match the listening port 8080
Go to Ingress Settings and change Target Port to match with the port your container is exposing at.
Eg: Change from 80 to 8080. Here 8080 is the port your app is running at or the app is exposing at.
If the error does not show up on the UI, you could check the logs from ContainerAppSystemLogs_CL table. The column name to check is Log_s.
If there are multiple Container Apps in the Container App Environment, better to filter by the Container App Name.
Sample Query:
ContainerAppSystemLogs_CL
| where ContainerAppName_s == 'album-api'
| project Time=TimeGenerated, EnvName=EnvironmentName_s, AppName=ContainerAppName_s, Revision=RevisionName_s, Message=Log_s
| take 100
The complete details of the query is available at Kusto Queries
To troubleshoot the issue further, you may refer - Container Apps - Target port does not match the listening port
Why do I get “Impossible to build the artifact file” error
When you run the “az containerapp up” command from your local machine and it returns the following error, check if Docker Desktop is running in your computer. If not, start running and execute the command again.
“Impossible to build the artifact file .\target\app.jar with ACR Task. Please make sure that you use –source and target a directory, or if you want to build your artifact locally, please make sure Docker is running on your machine.”
Why do I get “Java not supported” error
- Run ‘az upgrade’
- Once it is completed, you may get the following message.
Argument ‘–artifact’ is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus