Manage environment variables on Azure Container Apps
Artikkeli
In Azure Container Apps, you're able to set runtime environment variables. These variables can be set as manually entries or as references to secrets.
These environment variables are loaded onto your Container App during runtime.
Configure environment variables
You can configure the Environment Variables upon the creation of the Container App or later by creating a new revision.
Note
To avoid confusion, it is not recommended to duplicate environment variables. When multiple environment variables have the same name, the last one in the list takes effect.
If you're creating a new Container App through the Azure portal, you can set up the environment variables on the Container section:
You can create your Container App with environment variables using the az containerapp create command by passing the environment variables as space-separated 'key=value' entries using the --env-vars parameter.
If you want to reference a secret, you have to ensure that the secret you want to reference is already created, see Manage secrets. You can use the secret name and pass it to the value field but starting with secretref:
To use this cmdlet, you have to pass the name of the environment variable using the -Name parameter and the value using the -Value parameter, respectively.
If you want to reference a secret, you have to ensure that the secret you want to reference is already created, see Manage secrets. You can use the secret name and pass it to the -SecretRef parameter:
On this cmdlet, you have to pass the name of your container image (not the container app!) you desire using the -Name parameter, the fully qualified image name using the -Image parameter and reference the environment object you defined previously on the variable $envVar.
Please note that there are other settings that you might need to define inside the template object to avoid overriding them like resources, volume mounts, etc. Please check the full documentation about this template on New-AzContainerAppTemplateObject.
Finally, you can update your Container App based on the new template object you created using the Update-AzContainerApp PowerShell cmdlet.
In this last cmdlet, you only need to pass the template object you defined on the $containerTemplate variable on the previous step using the -TemplateContainer parameter.
Add environment variables on existing container apps
After the Container App is created, the only way to update the Container App environment variables is by creating a new revision with the needed changes.
If you want to create multiple environment variables, you can insert space-separated values in the 'key=value' format.
If you want to reference a secret, you have to ensure that the secret you want to reference is already created, see Manage secrets. You can use the secret name and pass it to the value field but starting with secretref:, see the following example:
Similarly to what you need to do upon creating a new Container App you have to create an object called EnvironmentVar, which is contained within a Container. This Container is then used with the New-AzContainerApp PowerShell cmdlet.
In this cmdlet, you only need to pass the template object you defined previously as described in the Configure environment variables section.
The DNS suffix for the Container Apps environment. To obtain the fully qualified domain name (FQDN) of the app, append the app name to the DNS suffix in the format $CONTAINER_APP_NAME.$CONTAINER_APP_ENV_DNS_SUFFIX.
<DEFAULT_HOSTNAME>.<REGION>.azurecontainerapps.io
CONTAINER_APP_PORT
The target port of the container app.
8080
CONTAINER_APP_REPLICA_NAME
The name of the container app replica.
my-containerapp--20mh1s9-86c8c4b497-zx9bq
Jobs
The following variables are available to Container Apps jobs: