2

I have a function app and am planning to use Azure KEDA for deployment. When converting the current function app to docker and testing the same in local using the docker run command, I get the below error.

Function host is not running.

It works while debugging in visual studio, but does not work in Docker. Other stackoverflow answers suggest check host.json and i tried it, but did not fix it.

Below is my host.json.

{
  "version": "2.0",
  "logging": {
    "fileLoggingMode": "always",
    "logLevel": {
      "default": "Information",
      "Host": "Error",
      "Function": "Error",
      "Host.Aggregator": "Information"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "maxTelemetryItemsPerSecond": 20
      }
    }
  }
}

DockerFile

FROM microsoft/dotnet:2.2-sdk AS installer-env

COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
    mkdir -p /home/site/wwwroot && \
    dotnet publish Projects/Projectxxx.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:2.0-appservice 
FROM mcr.microsoft.com/azure-functions/dotnet:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
Karthikeyan VK
  • 5,310
  • 3
  • 37
  • 50
  • Does this answer your question? [Function host is not running](https://stackoverflow.com/questions/49161601/function-host-is-not-running) – Trevor Dec 27 '19 at 14:02
  • no, already saw those. – Karthikeyan VK Dec 27 '19 at 14:14
  • 2
    Related doesn't answer your issue; can you perhaps tell us what you've tried so we're not wasting anyone's time then? You post lacks these details and would be of great help... On another note, what about the host log files, what do they tell you? – Trevor Dec 27 '19 at 14:16
  • it is in docker, so I could not see the log files. I have tried all the steps that is posted in the answer you suggested. – Karthikeyan VK Dec 27 '19 at 14:20
  • Might also be worth posting your Docker file? – Wim Dec 27 '19 at 14:21
  • have added docker file – Karthikeyan VK Dec 27 '19 at 14:22
  • Vanilla version created using `func init --docker` and no functions defined, works fine when running with docker. Can you try with the logging section removed from your host.json file? Just to eliminate a possible configuration issue... – Wim Dec 27 '19 at 15:09
  • Do you provide the whole Dockerfile? I do not see any CMD to run your application? – Charles Xu Dec 30 '19 at 02:46

1 Answers1

1

I did two things to make it work.

  • Add the <PackageReference Include="WindowsAzure.Storage" Version="9.3.2" /> to .csproj

enter image description here

  • Missed some environment variables. Some of the application settings were missing from docker run -e environment parameters, which was used in startup.cs
Karthikeyan VK
  • 5,310
  • 3
  • 37
  • 50
  • I am curious; exactly *how* did you discover the cause of the problem? I run into this problem regularly (see [Diagnose 'Function host is not running.' in docker][1]) [1]: https://stackoverflow.com/questions/67019463/diagnose-function-host-is-not-running-in-docker – TJ Galama Apr 09 '21 at 14:21
  • It was trail and error and luckily bumped into the solution – Karthikeyan VK Apr 11 '21 at 05:29
  • So there's no way to get logs from failing function runtime? – Karpik Mar 26 '22 at 01:08