TJ *_*ama 7 docker azure-webjobs .net-core azure-functions
我正在尝试将几个基于 dotnet 的功能应用程序 (v3) 迁移到 docker 容器。为此,我们使用mcr.microsoft.com/azure-functions/dotnet中的图像作为基础
当使用 docker run 进行本地测试时,我经常遇到这样的问题:对容器的 http 调用返回错误Function host is not running并结合以下 Docker CLI 输出:
Starting OpenBSD Secure Shell server: sshd.
Hosting environment: Development
Content root path: /home/site/wwwroot
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
Run Code Online (Sandbox Code Playgroud)
这仅仅意味着函数应用程序不会加载/启动,但真正的原因仍然隐藏。我一直在尝试获取更多日志记录/诊断数据来确定根本原因,但到目前为止失败了。因此,每当这种情况发生时,我都必须开始一个令人筋疲力尽的试错测试循环。到目前为止,这些情况已经花了我几天(几周?)
问题:发生此错误时如何获取更多诊断数据?
[更新] Dockerfile:
Starting OpenBSD Secure Shell server: sshd.
Hosting environment: Development
Content root path: /home/site/wwwroot
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
Run Code Online (Sandbox Code Playgroud)
在我弄清楚 TJ Galama 的评论之前,我遇到了同样的问题,并多次浏览了这个线程。
如何诊断启动失败的答案是将整个启动代码包装在 try/catch 块中:
[assembly: FunctionsStartup(typeof(My.Hr.Functions.Startup))]
namespace My.Hr.Functions;
public class Startup : FunctionsStartup
{
public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
}
public override void Configure(IFunctionsHostBuilder builder)
{
// try-catch to capture exceptions during startup when running in docker container
try
{
// Register the core services.
builder.Services
.AddSingleton<HrSettings>()
.AddExecutionContext();
// More setup code ...
}
catch (System.Exception ex)
{
System.Console.Error.WriteLine(ex);
throw;
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1305 次 |
| 最近记录: |