4

I am trying to run my timer trigger azure function sample using Docker. It works fine in the visual studio both in debug and release mode. But when use docker

docker run -d -p 8080:80 testdockercors

The application starts and it says the below message, but my timer trigger azure function is not running.

Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down..

But the timer trigger works fine, when running from visual studio. Please find my docker file.

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Testdockercors/Testdockercors.csproj", "Testdockercors/"]
RUN dotnet restore "Testdockercors/Testdockercors.csproj"
COPY . .
WORKDIR "/src/Testdockercors"
RUN dotnet build "Testdockercors.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Testdockercors.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV AzureWebJobsScriptRoot=/app
ENV AzureWebJobsStorage="UseDevelopmentStorage=true"

When I change the environment AzureWebJobsStorage value to an existing azure storage connection string it works in docker too. But i want to use the storage that is part of docker, not one available in azure.

Karthikeyan VK
  • 5,310
  • 3
  • 37
  • 50

2 Answers2

6

I fixed the issue by changing the value of AzureWebJobsStorage as below, appending DevelopmentStorageProxyUri=http://host.docker.internal to environment did the trick.

ENV AzureWebJobsStorage="UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://host.docker.internal"

You can read more about @ https://www.maneu.net/blog/use-local-storage-emulator-remote-container/

This will not work in Linux vm

Karthikeyan VK
  • 5,310
  • 3
  • 37
  • 50
1

I can confirm that using:

ENV AzureWebJobsStorage="UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://host.docker.internal"

works for the Python runtime (in particular mcr.microsoft.com/azure-functions/python:3.0-python3.7) as well.

In effect this resolves to the azurite endpoints running on the host where the docker runtime is running (in my case it is a macOS). Note that this does not imply that it will work if you run azurite in a container.

Mattia
  • 11
  • 1