使用自定义容器环境变量部署Azure Webapp [英] Deploy Azure Webapp with custom container environment variables

查看:177
本文介绍了使用自定义容器环境变量部署Azure Webapp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,我会在本地计算机上启动docker实例,例如docker run -t -i -e 'a=b' ...

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

现在,我想部署并运行我自定义的Docker映像,该映像之前已上传到Docker Container Registry,并像上面的命令一样使用环境变量启动它.

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.

检查 Azure CLI for WebApps ,您会看到一般应该设置环境变量.但是对我来说,这个环境变量"似乎不是传递给docker命令的环境变量.为什么?检查容器协议,我可以看到docker容器是如何启动的.没有设置环境变量.

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.

使用 Azure容器,它会像az container create ... --environment-variables a=b这样工作.这些环境变量被向下传递到容器/泊坞窗.这正是我要搜索的WebApp.

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.

有人在使用以环境变量开头的客户Docker实例部署Azure Webapp方面有经验吗?

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

推荐答案

我想我找到了解决问题的方法:

I guess I found the solution for the problem:

如果需要为应用程序设置环境变量,只需在Azure门户中添加应用程序设置.当您的应用运行时,我们会自动将应用设置作为环境变量注入到流程中.

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.

它如何通过CLI工作:

How it works via CLI:

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

像上面的命令一样,通过CLI设置所有环境变量对我来说很有效.通过应用程序设置中的门户网站UI可以实现相同的目的.如果检查Azure如何启动Docker实例,则将看到启动期间未设置任何设置的环境变量(例如docker run -d -p 3287:3000 --name <mycontainername -e a=b),但是如果您登录Docker容器并为环境变量运行echo命令,您将看到环境变量已被注入.

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.

注意:也许您必须重新启动Docker实例才能注入新的环境变量.

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

这篇关于使用自定义容器环境变量部署Azure Webapp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆