gpt4 book ai didi

.net - 使用 .NET 5 和 Docker 创建 Azure Functions

转载 作者:行者123 更新时间:2023-12-04 13:08:04 24 4
gpt4 key购买 nike

有一些使用隔离模型的 Azure 函数,运行为 an out-of-process language worker它与 Azure Functions 运行时分开。因为 Azure Functions 运行时尚不支持 .NET5。

  <PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>

我正在寻找一种将 .NET func 部署为 Docker 容器的方法。 enter image description here

func init LocalFunctionsProject --worker-runtime dotnet-isolated --docker 

对于 .NET 3.1,我有 Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS installer-env

COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
mkdir -p /home/site/wwwroot && \
dotnet publish *.csproj --output /home/site/wwwroot

FROM mcr.microsoft.com/azure-functions/dotnet:3.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]

如何容器化.NET5函数?有可能吗?有什么解决方法吗?我还没有找到解决方案。请推荐

最佳答案

好的,有两件事发生:

  1. 即使在 .NET 5.0 Functions 项目中,仍然存在对 .NET 3.1 Core SDK 的依赖,这 seems to be "by design."
  2. 我们使用 --worker-runtime = dotnet-isolated --docker is missing a key line to add the reference to .NET Core 3.1. 为项目生成的 Dockerfile

要解决此问题,请在 Dockerfile 中的第一个 FROM 语句之后添加以下行:

# Build requires 3.1 SDK
COPY --from=mcr.microsoft.com/dotnet/core/sdk:3.1 /usr/share/dotnet /usr/share/dotnet

Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS installer-env
COPY --from=mcr.microsoft.com/dotnet/core/sdk:3.1 /usr/share/dotnet /usr/share/dotnet

COPY ./LocalFunctionsProject/ /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
mkdir -p /home/site/wwwroot && \
dotnet publish *.csproj --output /home/site/wwwroot

FROM mcr.microsoft.com/azure-functions/dotnet-isolated:3.0-dotnet-isolated5.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]

The docs即将更新

关于.net - 使用 .NET 5 和 Docker 创建 Azure Functions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68460056/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com