Configuration in Azure Container App

François Baronnet 76 Reputation points
2021-11-14T13:05:45.94+00:00

How to define environment variables for Azure Container App (preview), via CLI or Portal?

I am asking specifically for Azure Container App, not Instances, but there is no such tag yet.

As of November 14th, 2021, there is nothing you can do from the Portal, at App or Environment level.

Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
643 questions
Azure App Configuration
Azure App Configuration
An Azure service that provides hosted, universal storage for Azure app configurations.
209 questions
Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
272 questions
0 comments No comments
{count} votes

Accepted answer
  1. SRIJIT-BOSE-MSFT 4,331 Reputation points Microsoft Employee
    2021-11-16T04:43:45.047+00:00

    @François Baronnet , thank you for your question.

    Currently you can define environment variables for your Azure Container Apps using Azure CLI or ARM template.

    Azure CLI:
    az containerapp create --help  
    Command  
        az containerapp create : Create a Containerapp.  
    ...  
    Container Arguments  
    ...      
        --environment-variables -v     : A list of environment variable(s) for the containerapp. Comma-  
                                         separated values in 'key=value' format. If there are multiple  
                                         containers, please use --yaml instead.  
    ...  
    Examples  
    ...  
        Create a Containerapp with secrets and environment variables  
            az containerapp create -n MyContainerapp -g MyResourceGroup \  
                --image MyContainerImage -e MyContainerappEnv \  
                --secrets mysecret=escapefromtarkov,anothersecret=isadifficultgame  
                --environment-variables myenvvar=foo,anotherenvvar=bar  
    

    Please check here for more information on setting up Azure CLI for Container Apps.

    ARM API Specification:

    The following is an example ARM template used to deploy a container app.

    {  
        "$schema": "https://schema.management.azure.com/schemas/2019-08-01/deploymentTemplate.json#",  
        "contentVersion": "1.0.0.0",  
        "parameters": {  
            "containerappName": {  
                "defaultValue": "mycontainerapp",  
                "type": "String"  
            },  
            "location": {  
                "defaultValue": "canadacentral",  
                "type": "String"  
            },  
            "environment_name": {  
                "defaultValue": "myenvironment",  
                "type": "String"  
            }  
        },  
        "variables": {},  
        "resources": [  
            {  
                "apiVersion": "2021-03-01",  
                "type": "Microsoft.Web/containerApps",  
                "name": "[parameters('containerappName')]",  
                "location": "[parameters('location')]",  
                "properties": {  
                    "kubeEnvironmentId": "[resourceId('Microsoft.Web/kubeEnvironments', parameters('environment_name'))]",  
                    "configuration": {  
                        "secrets": [  
                            {  
                                "name": "mysecret",  
                                "value": "thisismysecret"  
                            }  
                        ],  
                        "ingress": {  
                            "external": true,  
                            "targetPort": 80,  
                            "allowInsecure": false,  
                            "traffic": [  
                                {  
                                    "latestRevision": true,  
                                    "weight": 100  
                                }  
                            ]  
                        }  
                    },  
                    "template": {  
                        "revisionSuffix": "myrevision",  
                        "containers": [  
                            {  
                                "name": "nginx",  
                                "image": "nginx",  
                                "env": [  
                                    {  
                                        "name": "HTTP_PORT",  
                                        "value": "80"  
                                    },  
                                    {  
                                        "name": "SECRET_VAL",  
                                        "secretRef": "mysecret"  
                                    }  
                                ],  
                                "resources": {  
                                    "cpu": 0.5,  
                                    "memory": "1Gi"  
                                }  
                            }  
                        ],  
                        "scale": {  
                            "minReplicas": 1,  
                            "maxReplicas": 3  
                        }  
                    }  
                }  
            }  
        ]  
    }  
    

    For more information please check here.

    ----
    Hope this helps.

    Please "Accept as Answer" if it helped, so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful