Docker我用這個執行一個非常簡單的函式應用程式Dockerfile
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace fapp1
{
public static class HttpIngress
{
[FunctionName("Health")]
public static IActionResult Health([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "health")] HttpRequest req) => new OkObjectResult("OK");
[FunctionName("HttpIngress")]
[return: ServiceBus("%queuename%", Connection = "servicebusconnection")]
public static async Task<string> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req)
=> await new StreamReader(req.Body).ReadToEndAsync();
}
}
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS installer-env
# Build requires 3.1 SDK
COPY --from=mcr.microsoft.com/dotnet/core/sdk:3.1 /usr/share/dotnet /usr/share/dotnet
COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
mkdir -p /home/site/wwwroot && \
dotnet publish *.csproj --output /home/site/wwwroot
# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/dotnet:4-appservice
FROM mcr.microsoft.com/azure-functions/dotnet:4
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
docker run -it --env-file docker.env test
對于這兩個函式HttpIngress我得到這個錯誤:
fail: Host.Startup[0]
Error indexing method 'Health'
Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: Error indexing method 'Health'
---> System.InvalidOperationException: Method overloads are not supported. There are multiple methods with the name 'fapp1.HttpIngress.Health'.
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndex.Add(IFunctionDefinition function, FunctionDescriptor descriptor, MethodInfo method) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndex.cs:line 30
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsyncCore(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 349
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsync(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 149
--- End of inner exception stack trace ---
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsync(MethodInfo method, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 157
at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexTypeAsync(Type type, IFunctionIndexCollector index, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 85
fail: Function.Health[0]
Microsoft.Azure.WebJobs.Host: Error indexing method 'Health'. Microsoft.Azure.WebJobs.Host: Method overloads are not supported. There are multiple methods with the name 'fapp1.HttpIngress.Health'.
warn: Host.Startup[0]
Function 'Health' failed indexing and will be disabled.
我試過了
- 從
static類和方法更改為實體:無效 - 將每個函式/方法放入單獨的類中:這行得通,但這可能只是一種解決方法
- 在(默認設定為 on )和 current
Microsoft.NET.Sdk.Functions之間切換:無效4.0.1func init --worker-runtime dotnet --docker --language c#4.1.0
我現在在容器中運行 Functions 多年,但現在無法弄清楚我錯過了什么。
uj5u.com熱心網友回復:
我發現了你的問題,因為我有同樣的問題。它可能與此有關:
https://github.com/Azure/azure-functions-host/issues/8244
根據鏈接中的資訊,我更改了我的 dockerfile 以將此影像用于 azure 功能:
FROM mcr.microsoft.com/azure-functions/dotnet:4.1.3-slim
這讓它為我作業
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/446806.html
