【Azure Function App】解决Function App For Container 遇见ServiceUnavailable的异常
问题描述
在使用Terraform创建Function App 后,部署函数时候遇见 ServiceUnavailable (Bad Request -- Encountered an error (ServiceUnavailable) from host runtime.) 问题。
查看Function App的高级工具(Kudu)站点和默认站点,均出现 Application Error页面。
问题解答
查看Function App的Azure管理页面,有提示错误消息“ Configure Container Settings “ , 但是点击后,却没有任何反应, 无法查看具体的消息.
然后查看Function App的部署中心页面, 也是没有任何信息输出,页面空白。
根据此处判断,UI上一定有JS错误,所以启用浏览器开发者模式(F12),查看Console中的错误信息。发现报错:Incorrect fxVersion set in the site config: DOCKER。
判断出,是Function App for Container关于DOCKER的配置错误,所以对比一个正确的Function App Container发现关键信息为:
因为对LinuxFxVersion的配置只说明了DOCKER,没有指定正确的Image 路径,所以Function App 无法加载部署中心,同时也无法正确的运行DOCKER指令和Kudu站点。
解决办法
通过az functionapp config set 指令,修改 --linux-fx-version的值,如:
az functionapp config set --name <FUNCTION_APP> --resource-group <RESOURCE_GROUP> --linux-fx-version --% "DOCKER|mcr.microsoft.com/azure-functions/dotnet:4-appservice-quickstart"
(For Windows)注意:因为在Powershell中 ”|“是终止符,所以如果没有特殊说明,执行上面的语句会下面的错误:
'mcr.microsoft.com' is not recognized as an internal or external command, operable program or batch file.
所以,需要加上 停止分析 (
--%
) 标记来阻止 PowerShell 将输入解释为 PowerShell 命令:
或者是在Terraform中对linux-fx-version赋予完整的值。
linux_fx_version
- (Optional) Linux App Framework and version for the AppService, e.g.DOCKER|(golang:latest)
.
修改后,Function App页面恢复正常。
参考资料
Pin to a specific version on Linux: https://learn.microsoft.com/en-us/azure/azure-functions/set-runtime-version?tabs=portal#manual-version-updates-on-linux
Terraform设置Function App Linux fx version:https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app#linux_fx_version
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2022-11-06 【Azure 环境】Azure 云环境对于OpenSSL 3.x 的严重漏洞(CVE-2022-3602 和 CVE-2022-3786)的处理公告
2021-11-06 【Azure 存储服务】代码版 Azure Storage Blob 生成 SAS (Shared Access Signature: 共享访问签名)
2020-11-06 【应用程序见解 Application Insights】Application Insights 使用 Application Maps 构建请求链路视图