Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy Azure Webapp with custom container environment variables

Tags:

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?

like image 869
smichel Avatar asked Jun 04 '18 13:06

smichel


People also ask

How do I set environment variables in Azure container instance?

To set environment variables when you start a container in the Azure portal, specify them in the Advanced page when you create the container. Under Environment variables, enter NumWords with a value of 5 for the first variable, and enter MinLength with a value of 8 for the second variable.


Video Answer


1 Answers

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.

like image 151
smichel Avatar answered Oct 22 '22 08:10

smichel