8

I am trying to run a .Net Core based Azure Function inside a Docker container on a M1 Macbook without success so far.

Originally I used the Azure Function Core Tools CLI to create the function with the following command: func init LocalFunctionsProject --worker-runtime dotnet --docker which created the following 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"]

Building the Docker image and running as Container works just fine on a amd based machine. In the meanwhile I got myself a M1 Macbook on which running the Azure Function inside a Docker Container does not work anymore. It gives me the following exception:

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

What I tried so far

  1. Forcing Docker to use amd based base image by adding --platform=linux/amd64 to the FROM section of the first stage in the Dockerfile which gives me the following error message:
> [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. Changing the base image of the second stage to mcr.microsoft.com/azure-functions/dotnet:3.0-arm32v7 which gave me the following error:
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

Conclusion

My personal conclusion from how I understand the problem is that probably it will not work on my M1 machine unless there is a dedicated azure-function/dotnet image for arm64 v8 machines. If I am completely wrong, please hint me to the right direction.

MeBNoah
  • 165
  • 14

2 Answers2

0

You are correct. Unfortunately, the M1 architecture is not supported in your issue's scope. Please see this thread on GitHub and feel free to upvote it.

Arash
  • 3,628
  • 5
  • 46
  • 70
0

Issam Ben documented the instructions for running dotnet containers on M1/M2 macs:

  • Update docker to >= 4.16.2
  • Enable Use Rosetta for x86/amd64 emulation on Apple Silicon option in Settings > Features in development
  • Set platform to linux/amd64 when running docker build e.g. docker build --platform linux/amd64 ...

(edited quote for clarity)

I've used these settings to successfully run dotnet containers on my M1 mac.

nftw
  • 589
  • 4
  • 10