问题描述
我正在尝试在 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 镜像并作为容器运行在基于 amd 的机器上工作得很好。与此同时,我给自己买了一台 M1 Macbook,在 Docker 容器中运行 Azure 功能不再有效。它给了我以下异常:
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
到目前为止我尝试了什么
> [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
- 将第二阶段的基本图像更改为
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
结论
根据我对问题的理解,我个人得出的结论是,除非有用于 arm64 v8 机器的专用 azure-function/dotnet 映像,否则它可能无法在我的 M1 机器上运行。如果我完全错了,请提示我正确的方向。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)