0
0
Azurecloud~5 mins

Container Apps for microservices in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you want to run small parts of your app separately so they can work independently and scale easily, container apps help by running these parts in the cloud without managing servers.
When you want to split your app into smaller pieces that can be updated without stopping the whole app.
When you want each part of your app to handle different tasks and scale on its own.
When you want to run your app in the cloud without worrying about managing virtual machines.
When you want to connect different parts of your app securely and easily.
When you want to save money by only paying for the resources your app parts use.
Config File - containerapp.yaml
containerapp.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-microservice
  labels:
    app: my-microservice
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-microservice
  template:
    metadata:
      labels:
        app: my-microservice
    spec:
      containers:
      - name: my-microservice
        image: mcr.microsoft.com/azuredocs/containerapps-helloworld:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: my-microservice-service
spec:
  selector:
    app: my-microservice
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  type: ClusterIP

This file defines a simple microservice deployment and a service to expose it inside the container app environment.

Deployment: Runs one copy of the microservice container.

Service: Allows other parts of the app to communicate with this microservice on port 80.

Commands
This command creates a container app named 'my-microservice' in the resource group 'my-resource-group' using the specified container image. It opens port 80 to allow external access.
Terminal
az containerapp create --name my-microservice --resource-group my-resource-group --environment my-env --image mcr.microsoft.com/azuredocs/containerapps-helloworld:latest --target-port 80 --ingress external
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-resource-group/providers/Microsoft.App/containerApps/my-microservice", "name": "my-microservice", "properties": { "configuration": { "ingress": { "external": true, "targetPort": 80 } }, "provisioningState": "Succeeded" }, "type": "Microsoft.App/containerApps" }
--name - Sets the name of the container app
--resource-group - Specifies the Azure resource group to use
--ingress - Defines if the app is accessible externally or only inside the environment
This command shows details about the container app to verify it was created and is running.
Terminal
az containerapp show --name my-microservice --resource-group my-resource-group
Expected OutputExpected
{ "name": "my-microservice", "resourceGroup": "my-resource-group", "properties": { "provisioningState": "Succeeded", "configuration": { "ingress": { "external": true, "targetPort": 80 } }, "latestRevisionFqdn": "my-microservice.eastus.azurecontainerapps.io" } }
--name - Specifies the container app name to show
--resource-group - Specifies the resource group of the container app
This command tests that the container app is reachable by sending a web request to its public address.
Terminal
curl https://my-microservice.eastus.azurecontainerapps.io
Expected OutputExpected
Hello from Azure Container Apps!
Key Concept

If you remember nothing else from this pattern, remember: container apps let you run small, independent parts of your app in the cloud without managing servers.

Common Mistakes
Not specifying the resource group when creating or showing the container app
Azure needs the resource group to find or create the container app; missing it causes errors.
Always include the --resource-group flag with the correct group name.
Forgetting to open the ingress port for external access
Without ingress set to external and the target port open, the app won't be reachable from outside.
Use --ingress external and --target-port with the correct port number when creating the app.
Using an incorrect or unavailable container image
The container app won't start if the image cannot be pulled from the registry.
Use a valid, publicly available container image or one from your own registry with proper access.
Summary
Create a container app with az containerapp create, specifying name, resource group, image, and ingress settings.
Check the app status and details with az containerapp show to confirm it is running.
Test the app by sending a request to its public URL to ensure it responds correctly.