Bird
Raised Fist0
Azurecloud~5 mins

Container Apps for microservices in Azure - Commands & Configuration

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. What is the main benefit of using Azure Container Apps for microservices?
easy
A. They let you run small parts of an app separately and scale them easily.
B. They require you to manage all the servers manually.
C. They combine all app parts into one big container.
D. They only work for apps without any updates.

Solution

  1. Step 1: Understand microservices in Azure Container Apps

    Azure Container Apps allow running small, separate parts of an app independently.
  2. Step 2: Identify the benefit of scaling and updating

    This setup lets you scale and update parts without affecting the whole app, and Azure manages the servers.
  3. Final Answer:

    They let you run small parts of an app separately and scale them easily. -> Option A
  4. Quick Check:

    Microservices = separate, scalable parts [OK]
Hint: Microservices run small parts separately for easy scaling [OK]
Common Mistakes:
  • Thinking you must manage servers yourself
  • Believing all parts run in one container
  • Assuming no updates are possible
2. Which of the following is the correct way to define a container app in Azure CLI?
easy
A. az container create --name myapp --resource-group mygroup --image myimage:latest
B. az containerapp deploy --name myapp --resource-group mygroup --image myimage:latest
C. az appcontainer create --name myapp --resource-group mygroup --image myimage:latest
D. az containerapp create --name myapp --resource-group mygroup --image myimage:latest

Solution

  1. Step 1: Identify the correct Azure CLI command for Container Apps

    The correct command to create a container app is az containerapp create.
  2. Step 2: Check the command syntax

    The command includes the app name, resource group, and image, matching az containerapp create --name myapp --resource-group mygroup --image myimage:latest exactly.
  3. Final Answer:

    az containerapp create --name myapp --resource-group mygroup --image myimage:latest -> Option D
  4. Quick Check:

    Container Apps use 'az containerapp create' [OK]
Hint: Use 'az containerapp create' to define container apps [OK]
Common Mistakes:
  • Using 'az container create' which is for regular containers
  • Typing 'appcontainer' instead of 'containerapp'
  • Using 'deploy' instead of 'create' command
3. Given this Azure CLI command:
az containerapp create --name orderservice --resource-group shoprg --image shop/orders:1.0 --cpu 0.5 --memory 1.0

What resource limits are set for this container app?
medium
A. 0.5 CPU cores and 1.0 GB memory
B. 1 CPU core and 0.5 GB memory
C. 0.5 CPU cores and 0.5 GB memory
D. 1 CPU core and 1.0 GB memory

Solution

  1. Step 1: Read the CPU and memory flags in the command

    The command sets --cpu 0.5 and --memory 1.0.
  2. Step 2: Interpret the values

    CPU is 0.5 cores, memory is 1.0 GB as per the flags.
  3. Final Answer:

    0.5 CPU cores and 1.0 GB memory -> Option A
  4. Quick Check:

    CPU=0.5, Memory=1.0 GB [OK]
Hint: Match --cpu and --memory values exactly [OK]
Common Mistakes:
  • Swapping CPU and memory values
  • Assuming units are in MB instead of GB
  • Ignoring the flags and guessing defaults
4. You tried to deploy a container app with this command:
az containerapp create --name paymentapp --resource-group payrg --image pay/image:latest --cpu two --memory 1.5

What is the likely problem?
medium
A. The memory value 1.5 is too low; it must be at least 2 GB.
B. The CPU value 'two' is invalid; it should be a number like 2 or 0.5.
C. The image tag 'latest' is not allowed in Azure Container Apps.
D. The resource group name 'payrg' is invalid.

Solution

  1. Step 1: Check the CPU parameter format

    The CPU value must be a number (like 0.5 or 2), not a word.
  2. Step 2: Identify the error in the command

    Using 'two' instead of a numeric value causes a syntax error.
  3. Final Answer:

    The CPU value 'two' is invalid; it should be a number like 2 or 0.5. -> Option B
  4. Quick Check:

    CPU must be numeric [OK]
Hint: CPU must be a number, not a word [OK]
Common Mistakes:
  • Using words instead of numbers for CPU
  • Assuming 'latest' tag is invalid
  • Thinking resource group name is the problem
5. You want to deploy a microservice architecture using Azure Container Apps with three services: frontend, backend, and database. You want each to scale independently and update without downtime. Which approach is best?
hard
A. Deploy only the frontend as a container app and run backend and database on VMs.
B. Combine all services into one container app to simplify management.
C. Deploy each service as a separate container app with its own scaling rules.
D. Use Azure Container Instances for all services instead of Container Apps.

Solution

  1. Step 1: Understand microservice deployment goals

    Each service should scale independently and update without downtime.
  2. Step 2: Evaluate deployment options

    Deploying each service as a separate container app allows independent scaling and updates.
  3. Step 3: Rule out other options

    Combining services loses independent scaling; mixing VMs adds complexity; Container Instances lack built-in scaling features.
  4. Final Answer:

    Deploy each service as a separate container app with its own scaling rules. -> Option C
  5. Quick Check:

    Separate apps = independent scaling and updates [OK]
Hint: Separate container apps for each microservice [OK]
Common Mistakes:
  • Combining all services in one container app
  • Mixing container apps with VMs unnecessarily
  • Using Container Instances which lack scaling