Deploy Azure Webapp with custom container environment variables

12,677

I guess I found the solution for the problem:

App Settings are injected into your app as environment variables at runtime.

If you need to set an environment variable for your application, simply add an App Setting in the Azure portal. When your app runs, we will inject the app setting into the process as an environment variable automatically.

How it works via CLI:

az webapp config appsettings set --name <mycontainername> --resource-group <myresourcegroupname> --settings a='b' 

Setting all environment variables via CLI like the command above worked for me. The same is possible via the portal UI in app settings. If you check how Azure starts the Docker instance, you will see that none of the set environment variables are set during startup (like.docker run -d -p 3287:3000 --name <mycontainername -e a=b) but if you login to the Docker container and run an echo command for the environment variable, you will see that the environment variable has been injected.

Note: Maybe you have to restart the Docker instance in order to have the new environment variables injected.

Share:
12,677

Related videos on Youtube

smichel
Author by

smichel

Updated on September 23, 2022

Comments

  • smichel
    smichel over 1 year

    In general, I would start the docker instance on my local machine like docker run -t -i -e 'a=b' ...

    Now, I would like to deploy and run my custom docker image which I uploaded to the Docker Container Registry before and start it like the command above - with environment variables.

    Checking the Azure CLI for WebApps you can see that setting environment variables in general should be possible. But for me it seems this "environment variables" are not the environment variables which are passed to the docker command. Why? Checking the container protocol I can see how the docker container is started. There are no environment variables set.

    With Azure Container, it would work like this az container create ... --environment-variables a=b. These environment variables are passed down to the container/docker. And this is exactly what I am searching for WebApps.

    Does anyone have some experience in deploying Azure Webapps with customer Docker instances started with environment variables?

  • coderpatros
    coderpatros over 5 years
    This had me absolutely pulling my hair out. When I ssh into the running container and printenv the appsettings are not visible. But they do seem to be available to the container entry point. I ended up adding a echo $TEST > test.txt to my entry point. Although they weren't available straight away. It took a couple of container restarts.
  • Jose
    Jose about 3 years
    Same here... I do not see the vars in the container
  • thxmike
    thxmike about 3 years
    This does not work for me via the Web UI.