I'm having a hard time finding where I can set custom environment variables that docker run will pass to my custom docker image. My image reads config from those environment variables.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@timmydo Thanks for the feedback. We are actively investigating and will get back to you soon.
Hey @timmydo - I will look into this today and share any relevant findings. Just to clarify, are you not setting environment variables in your Dockerfile
using ENV
before uploading your custom image to Azure Container Registry? Also, check out following docs if you haven't seen them:
Setting environment variables in your container instances
https://docs.microsoft.com/en-us/azure/container-instances/container-instances-using-azure-container-registry
Deploy to Azure Container Instances from Azure Container Registry
https://docs.microsoft.com/en-us/azure/container-instances/container-instances-environment-variables
Thanks for the links. I think they may be more geared towards running containers independently. In my scenario, I'm running a container inside the web app service, so I can't use some of those commands. (I'm guessing the web app service starts my container and forwards http requests to port 80 on it)
I'm not setting env vars in my dockerfile because my dockerfile is checked into a public git repository and I don't want to put secrets there. I suppose I could work around it by creating another secret dockerfile with environment variables, but it would be more convenient to put it into the azure portal (maybe in the azure web app application settings section?).
@timmydo Yup, definitely not ideal when on a public repo. So the configuration values (key, value pairs) defined through app settings are made available to your application at its runtime as environment
variables, not during deployment time. You may use Azure Key Vault
service in your Dockerfile
to fetch the config values but you'd still need to expose tenant_id
, subscription_id
etc in your Dockerfile (unless you choose to define them into separate env
file that doesn't get checked into your repo).. Here's one example in case this scenario is helpful:
With that said, check out the following doc where it discusses defining a custom deployment (build process) with VSTS to Web App for Containers:
Why use a separate release definition instead of the automatic deployment feature available in Web App for Containers?
https://docs.microsoft.com/en-us/vsts/build-release/apps/cd/deploy-docker-webapp?view=vsts
That doc links to a doc telling you how to build a container using VSTS, but that doc explaining how to build a container with a VSTS step doesn't mention anything about handling secrets/environment variables. The VSTS task to build a docker image requires a dockerfile that's checked into the repository.
I could have an inline powershell script generate a dockerfile somewhere before running the docker build step, but it seems like a hack. I think this is mostly docker's fault
Maybe an alternative is to use a kubernetes pod yaml definition in the web app in the azure portal to define the environment variables, but I can't find any good docs on that. It doesn't seem like the right place to put config since I think those pod definitions make more sense checked into source control.
Who would be the right person to make a feature request to allow passing of env vars to the docker run command in the azure portal?
@neilpeterson would happen to have any insights into this? I know it is technically a web-app doc but it is in regards to containers so thought it might be worth an ask
I've not worked with web-apps myself, however quick scan of the doc shows that we can used --settings
when using the CLI.
--settings WEBSITES_PORT=8000
Looking at the portal, I do not see a very straight forward way of accomplishing this. As @timmydo has pointed out, looks like we can consume a Docker Compose or Kubernetes manifest file, which should both do the trick.
So a compose file like this should work (I've confirmed).
version: '3'
services:
demo-env:
image: microsoft/sample-aks-helloworld
container_name: aks-helloworld
environment:
TITLE: test-environment-var
That said, I would also expect something more basic, similar to the --settings
CLI argument.
@SyntaxC4 and thoughts on this one?
@timmydo we solved this using the azure cli to set our Application Setting variables. All those variables end up in the environment of the launched docker cmd/entrypoint. e.g
az webapp config appsettings set --name webapp-name --resource-group dev --settings DB_NAME=dbname DB_HOST=ourhost.database.windows.net DB_USER=dbuser DB_PASSWD=passwd WEBSITES_ENABLE_APP_SERVICE_STORAGE=true
So at least they aren't in source control.
@saschwarz I don't think azure application settings are passed to -e
options in the docker run
command for container web apps?
@timmydo Maybe we are talking about different ways to run docker containers in Azure? In WebApps for Containers I don't issue docker run
. I push the image to our private azure registry, select the tag in the WebApp instance w/in the portal (or via the azure cli) and its is deployed/run with the application settings injected into the environment:
@timmydo Please submit a feature request at Azure Feedback site so that the community can upvote this feature & our product team can review for future implementation.
We will now proceed to close this thread. If there are further questions regarding this matter, please reopen it and we will gladly continue the discussion.
This topic is exactly what I was/am searching for days. In the end I put a question on stackoverflow (https://stackoverflow.com/questions/50681821/deploy-azure-webapp-with-custom-container-environment-variables) in order to get an answer to my question.
My workaround was also using a docker-compose file but with docker-compose it is not (yet) possible to use ACR images.
Same question here. For now, I just want to say: stupid azure!
Hi everyone,
Any workaround on this topic ?, we are facing the same issue in 2019 while trying to pass environment variables (parameters) to my private docker image through an App Service, Web App for Container or simple Containers in Azure... it is always the same failing output
Use application settings under the configuration tab in sectuon settings in app service. Every application setting is passed to the container as an env variable.
We are still seeing an issue where our .nercore app within a container that being pulled from ACR is not picking up the app settings from the App Service within the Azure portal. The values are not automatically being injected at run time as the documentation suggests.
I feel like being able to add environment variables to the docker run
command is a very basic and essential feature.
I am not surprised that again Azure manages to turn something trivial into an issue which takes me way too long to fix.
We are using applications settings to inject variables to custom docker images and docker compose apps for 5 months now without any issue...
When I tail the log stream
of my container, I can see the actual command that is ran in order to spin the container up. While it does contain the following ENV_VARS
, the ones I set as application settings are still missing.
docker run -d -p 7312:80 --name container_name -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=appservice-name -e WEBSITE_AUTH_ENABLED=False -e PORT=80 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=appservice-name.azurewebsites.net -e WEBSITE_INSTANCE_ID=INSTANCE_ID -e HTTP_LOGGING_ENABLED=1 repo.azurecr.io/container:tag
It seems like the environment variables are injected when the entrypoint is ran though, but afterwards they're not accessible anymore. Highly annoying.
Having the same issue after a deployment and can't get it back online. production has been down for 5 hours
Most helpful comment
Same question here. For now, I just want to say: stupid azure!