Deploy Azure Webapp with custom container environm

2019-02-25 13:36发布

问题:

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?

回答1:

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> --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.