Deploy Azure Webapp with custom container environment variables
Asked Answered
O

1

30

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?

Oligarchy answered 4/6, 2018 at 13:30 Comment(0)
O
30

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.

Oligarchy answered 6/6, 2018 at 8:28 Comment(5)
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.Hawthorne
Same here... I do not see the vars in the containerHubbub
This does not work for me via the Web UI.Nodus
I just gave up. Noticed Azure runs two containers - Kudu (managed by Azure) and custom container. All the settings can go to Kudu automatically but it does not work with custom container.Rasping
@Hawthorne is correct. All the appsettings can be captured at entry point even for custom container service. You can save the environment variables into a file and then re-inject to your environment if necessary. Also noticed managed identity can also work with the environment variables at entry point.Rasping

© 2022 - 2024 — McMap. All rights reserved.