自定义入口点后如何在Docker中启动.NET 8独立版Azure Function?
.NET 8独立版Azure Function自定义入口脚本后启动问题解决
问题原因
- 隔离模式的Azure Function不能直接运行你的函数项目dll(如
myfunction.dll),必须启动官方提供的宿主程序Microsoft.Azure.Functions.Worker.dll func start属于Azure Functions Core Tools命令,该生产镜像未预装此工具,因此无法调用
解决方案
方案1:直接在入口脚本中启动宿主程序
修改你的entrypoint.sh,将最后一行的注释替换为以下命令:
# 启动Azure Functions隔离模式宿主 exec dotnet /home/site/wwwroot/Microsoft.Azure.Functions.Worker.dll
方案2:通过CMD传递启动命令(更灵活)
- 修改Dockerfile,在ENTRYPOINT后添加CMD指令:
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS installer-env ARG BUILD_CONFIGURATION=Release WORKDIR /src COPY ["myfunction/myfunction.csproj", "myfunction/"] COPY . . RUN dotnet publish "./myfunction/myfunction.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-isolated:4-dotnet-isolated8.0-appservice FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0 ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ AzureFunctionsJobHost__Logging__Console__IsEnabled=true COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"] COPY ["myfunction/entrypoint.sh", "."] RUN chmod +x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] CMD ["dotnet", "/home/site/wwwroot/Microsoft.Azure.Functions.Worker.dll"]
- 修改
entrypoint.sh,最后一行改为:
exec "$@"
此配置下,自定义启动任务执行完毕后,会自动运行Dockerfile中CMD指定的Azure Function宿主启动命令,后续如需调整启动参数,仅需修改CMD即可。
内容的提问来源于stack exchange,提问作者MilleB
相关产品推荐
相关产品推荐

