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

查看:21
本文介绍了使用自定义容器环境变量部署 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 映像,并像上面的命令一样使用环境变量启动它.

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.

使用 AzureContainer,它的工作方式类似于 az container create ... --environment-variables a=b.这些环境变量被传递给容器/docker.这正是我正在寻找的 WebApps.

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.

有没有人在部署 Azure Webapps 以及从环境变量开始的客户 Docker 实例方面有一些经验?

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 ) 但是如果你登录到 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天全站免登陆