【问题标题】:Creating Azure Functions using .NET 5 and Docker使用 .NET 5 和 Docker 创建 Azure Functions
【发布时间】:2021-09-28 06:31:33
【问题描述】:

有一些使用独立模型的 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 容器的方法。

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 函数容器化?甚至可能吗?任何解决方法?我还没有找到解决方案。请推荐

【问题讨论】:

    标签: .net azure docker .net-core azure-functions


    【解决方案1】:

    好的,所以有两件事发生:

    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 即将更新

    【讨论】:

      猜你喜欢
      • 2021-08-22
      • 2021-07-06
      • 1970-01-01
      • 2022-06-21
      • 2023-02-16
      • 1970-01-01
      • 2021-08-04
      • 2022-07-06
      • 2021-08-09
      相关资源
      最近更新 更多