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

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

有一些使用隔离模型的 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/

相关文章:

c# - 如何将指向 JavaScript 文件的链接添加到特定 ASP .NET MVC 页面的页眉中

Azure CDN 规则引擎重写默认文档并删除 .html 扩展名

docker - 当 Docker 容器发布端口时,应用程序使用 IP 而不是主机名在 Eureka 中注册

docker - 带有 .net core 3.1 Web 应用程序的 docker 容器问题

docker - 如何防止主机操作系统的根访问容器内的内容?

c# - Npgsql 奇怪的异常

.net - WPF 4.5 父子行为是否改变 : we can now add a child to another parent without exception?

c# - 寻找循环列表解决方案

android - 从 Azure 获取结果,插入一行并在插入 Azure 数据库后从本地数据库删除行数据

c# - 使用客户端 key 的 Azure 和 Microsoft Graph : Access denied accessing inbox,