Deploying Docker Containers to Azure with Different Environment Variable Files

johananmahendran 120 Reputation points
2025-01-25T08:03:23.0366667+00:00

I have built a Docker image which I plan on deploying to Azure Container Instances.

The Docker image has a .env which stores all the keys and variables that it needs to function. I have two different production environment variable files (.env.prod1 and .env.prod2) and the goal is to deploy separate containers using each of these environment variable sets. These environment variable files are 50+ lines long, so I would prefer not to use the az container create --environment-variable argument if it means I have to list down each variable.

What would be the best way to go about this?

Currently, it seems like I need to:

  1. Create an image with .env.prod1 copied in.
  2. Push this image (imageprod1:latest) to ACR and create an Azure Container Instance with the newly pushed image.
  3. Swap out .env.prod1 with .env.prod2, and create a new image.
  4. Deploy this new image (imageprod2:latest) to ACR and create an Azure container Instance with this image.

This seems inefficient and not as modular as I expect, and maybe there's a way to push one image and leverage Azure to specify the environment variables?

I am programming using VS Code and my code is in Python 3.11. I am comfortable with using the Azure CLI.

Thank you!

Azure Container Registry
Azure Container Registry
An Azure service that provides a registry of Docker and Open Container Initiative images.
478 questions
Azure Container Instances
Azure Container Instances
An Azure service that provides customers with a serverless container experience.
722 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.