I have a .net core 5.0 application wrapped in a docker image, I can run the image as a container under Docker Desktop with Linux Container mode, when I am stopping the container app is able to catch following events, which is what I want.
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += ctx =>
{
Console.WriteLine("Unloading");
};
AppDomain.CurrentDomain.ProcessExit += (s, e) =>
{
Console.WriteLine("Exitting");
};
However once I push the docker image to the azure registry and start as Azure container instance, neither stopping or restart via button in portal.azure trigger these events. Same issue for azure cloud shell commands.
az container restart --name gracefullApp --resource-group gracefullAppGroup
az container stop --name gracefullApp --resource-group gracefullAppGroup
Any idea how can this be achieved?
The dockerfile is generated by VS2019
FROM mcr.microsoft.com/dotnet/runtime:5.0-buster-slim AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["gracefullApp/gracefullApp.csproj", "gracefullApp/"]
RUN dotnet restore "gracefullApp/gracefullApp.csproj"
COPY . .
WORKDIR "/src/gracefullApp"
RUN dotnet build "gracefullApp.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "gracefullApp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "gracefullApp.dll"]