How to add .env file to container app

Umesh Edirisingha 0 Reputation points
2024-05-10T07:51:55.32+00:00

I have laravel container image.and going to use container app.how to add env to this container app. can't use azure portal,i have 50+ environment variables. Right now i have .env file

Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
324 questions
Azure Startups
Azure Startups
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.Startups: Companies that are in their initial stages of business and typically developing a business model and seeking financing.
236 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 13,951 Reputation points
    2024-05-13T15:46:02.9666667+00:00

    Hi @Umesh Edirisingha Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    Azure Container Apps also provides couple of different options through Azure CLI or Powershell to Add/Update environment variables.

    While creating a Container App you can use the following Azure CLI command to pass multiple environment variables by a space-separated values in the 'key=value' format.

    az containerapp create -n my-containerapp -g MyResourceGroup \
        --image my-app:v1.0 --environment MyContainerappEnv \
        --secrets mysecret=secretvalue1 anothersecret="secret value 2" \
        --env-vars GREETING="Hello, world" ANOTHERENV=anotherenv
    
    

    If you are trying to provide environment variables to an existing Container App, you may az containerapp update command and achieve the same. Please refer the document link to get more information on how to Configure the environment variables through Azure CLI

    Here is another option to Configure the environment variables through Powershell

    You can iterate the contents of your .env file through the following script and automate the addition of entries.

    Get-Content .env | ForEach-Object {
        # Split the line into the variable name and value
        $varName, $varValue = $_.Split('=')
    
        # Do something with the variable name and value
        Write-Host "Variable name: $varName, Value: $varValue"
        # Put in the commands from configuring through PowerShell option
    
        # Wait for 5 second
        Start-Sleep -Seconds 5
    }
    

    Please note that I have put a five second delay in the above loop as the script iterates through the file contents and call Update-AzContainerApp -TemplateContainer $containerTemplate command. This is just a caution to allow the command execution to be done processing adding an environment value. Please test this script on a test app and adjust the wait time as needed.

    Hope this helps! Please let us know if you need any additional assistance or have further questions in the comments below.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.