Container Apps - Referencing env vars through other environment variables

less than 1 minute read | By Anthony Salemo

This post will quickly go over how to add environment variables to Azure Container Apps that reference other environment variables

Overview

With Azure Container Apps, you can add environment variables that reference other environment variables you’ve created - you can also reference “pre-existing” environment variables (these are generally the Kubernetes-based ones injected into containers within a pod).

The syntax to do this is: $(MY_REFERENCED_ENV_VAR)

Casing doesn’t matter, by the syntax of $() is what ultimately makes this work. Below is an example:

Environment variables in containers

We have the environment variables with their key/value pairs of:

  • ENV_VAR_A: firstvalue
  • ENV_VAR_B: secondvalue
  • ENV_VAR_CONCAT: $(ENV_VAR_A)

If we go into Console and run something like env, we can see this value expands appropriately:

Expanded and concatenated env var

You can do this with “pre-existing” environment variables too. This example uses CONTAINER_APP_REVISION as the value, which can we can see gets expanded:

Prepopulated env var

Prepopulated and concatenated env var