在Apple Silicon上的Docker容器中运行基于.Net Core的Azure函数

kmbjn2e3  于 2023-04-20  发布在  Docker
关注(0)|答案(1)|浏览(116)

我试图在M1 MacBook上的Docker容器内运行基于.Net Core的Azure函数,但到目前为止没有成功。
最初,我使用Azure Function Core Tools CLI通过以下命令创建函数:func init LocalFunctionsProject --worker-runtime dotnet --docker创建了以下Dockerfile。

FROM mcr.microsoft.com/dotnet/core/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

# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/dotnet:3.0-appservice
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"]

构建Docker镜像并作为Container运行在基于amd的机器上运行得很好。与此同时,我给自己买了一台M1 Macbook,在Docker Container中运行Azure Function不再起作用。它给了我以下例外:

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Unhandled exception. System.IO.IOException: Function not implemented
   at System.IO.FileSystemWatcher.StartRaisingEvents()
   at System.IO.FileSystemWatcher.StartRaisingEventsIfNotDisposed()
   at System.IO.FileSystemWatcher.set_EnableRaisingEvents(Boolean value)
   at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.TryEnableFileSystemWatcher()
   at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.CreateFileChangeToken(String filter)
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider.Watch(String filter)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.<.ctor>b__1_0()
   at Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration`1..ctor(Func`1 changeTokenProducer, Action`1 changeTokenConsumer, TState state)
   at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider..ctor(FileConfigurationSource source)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationSource.Build(IConfigurationBuilder builder)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at Microsoft.Azure.WebJobs.Script.WebHost.Program.BuildWebHost(String[] args) in /src/azure-functions-host/src/WebJobs.Script.WebHost/Program.cs:line 35
   at Microsoft.Azure.WebJobs.Script.WebHost.Program.Main(String[] args) in /src/azure-functions-host/src/WebJobs.Script.WebHost/Program.cs:line 25
qemu: uncaught target signal 6 (Aborted) - core dumped

我一直在努力

1.通过将--platform=linux/amd64添加到Dockerfile中第一阶段的FROM部分来强制Docker使用基于amd的基础镜像,这给了我以下错误消息:

> [installer-env 3/3] RUN cd /src/dotnet-function-app &&     mkdir -p /home/site/wwwroot &&     dotnet publish *.csproj --output /home/site/wwwroot:                               
#9 3.258 Microsoft (R) Build Engine version 16.7.2+b60ddb6f4 for .NET
#9 3.258 Copyright (C) Microsoft Corporation. All rights reserved.
#9 3.258 
#9 3.441 qemu: uncaught target signal 11 (Segmentation fault) - core dumped
#9 3.456 Segmentation fault
------
executor failed running [/bin/sh -c cd /src/dotnet-function-app &&     mkdir -p /home/site/wwwroot &&     dotnet publish *.csproj --output /home/site/wwwroot]: exit code: 139

1.将第二阶段的基础图像更改为mcr.microsoft.com/azure-functions/dotnet:3.0-arm32v7,这给了我以下错误:

WARNING: The requested image's platform (linux/arm) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
A fatal error occurred, the folder [/usr/share/dotnet/host/fxr] does not contain any version-numbered child folders

总结

我个人的结论是,从我如何理解这个问题是,它可能不会在我的M1机器上工作,除非有一个专门的azure-function/dotnet图像为arm 64 v8机器。如果我完全错了,请提示我正确的方向。

3zwtqj6y

3zwtqj6y1#

你是对的。不幸的是,M1架构在你的问题范围内不受支持。请在GitHub上查看此线程并随时支持它。

相关问题