I’m trying to get an isolated worker model Azure function to run in a container, but it fails with the following error:
Unhandled exception. System.InvalidOperationException: The gRPC channel URI ‘http://:’ could not be parsed.
Here is my dockerfile
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["Email.Function/Email.Function.csproj", "Email.Function/"]
RUN dotnet restore "Email.Function/Email.Function.csproj"
COPY . .
RUN dotnet build "Email.Function/Email.Function.csproj" -c Release -o /app/build
RUN dotnet publish "Email.Function/Email.Function.csproj" -c Release -o /app/publish
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0
WORKDIR /home/site/wwwroot
COPY --from=build /app/publish .
CMD ["dotnet", "Email.Function.dll", "--dotnet-isolated"]
I saw some workarounds was to add the following environment variables but this also didn’t work
ENV FUNCTIONS_WORKER_GRPC_URI=http://127.0.0.1:5000
ENV WEBSITE_USE_PLACEHOLDER_DOTNETISOLATED=0
I can run and debug the function without using docker, but it fails inside a container.
2
Answers
The error could be due to the misconfiguration with the communication between the Azure Functions worker and the runtime.
I have created a .NET 8.0 Dotnet-isolated Azure function and dockerized the function using the Dockerfile as below:
Dockerfile:
Docker image for the function:
Able to run the function in container:
I have a local Docker host running a container with a .NET8 Isolated Azure Functions project. It has HTTP Trigger and Timer Trigger functions.
My Dockerfile for x64 is as follows:
In my case I’m running it in a slightly unusual way: in a local Docker host, rather than in Azure. So, it might not be close enough to your environment. But hopefully you can at least take some inspiration from it, if it’s not a perfect match.
I’ve used this same Dockerfile successfully on local Docker hosts for both x64 and also ARM64v8 on RPi. (although for the latter there’s no official Docker image for .NET8 Isolated, so I’m using a 3rd party one.)