How to do gracefully shutdown on dotnet with docker?

Is there a way to gracefully shut-down a DOTNET CORE application which is running in DOCKER? If yes, which event I should listen?

All I want is upon cancellation request I would like to pass my cancellation token/s to current methods and postpone the shut-down while they are working.

  • Catching 404 and redirect to wwwroot
  • dotnet core on docker performance
  • How are people authenticated in their ASP.NET Core Web APIs on Ubuntu/Docker given the bug described below?
  • Bitbucket Pipelines. Cannot specify windowsservercore docker image
  • Can containers share a framework?
  • Build custom Docker microsoft dotnet image with NuGet packages already downloaded
  • Looking for a sample code, reference link etc. which are relevant to dotnet core and not generic info

    UPDATE
    This question is not a duplicate of docker container exits immediately even with Console.ReadLine() in a .net core console application because I’m not having an immediate exit issue. I need to tap into event something like Windows.SystemsEvents.SessionEnding and relying on Console.CancelKeyPress and/or implementing WebHostBuilder() doesn’t fit the bill.

  • Using MongoDB Docker on .NET Core
  • Debug ASP.NET Core on Docker in Visual Studio Code
  • How are people authenticated in their ASP.NET Core Web APIs on Ubuntu/Docker given the bug described below?
  • How to restore nuget packages from network share in Linux Docker container
  • Docker .Net Core app on Ubuntu not opening in localhost:8000
  • Cannot find Application Insights dependency in docker image after dotnet publish
  • One Solution collect form web for “How to do gracefully shutdown on dotnet with docker?”

    System.Console has an event called CancelKeyPress. I believe this is fired when a sigint event is passed into dotnet.

    System.Console.CancelKeyPress += (s,e) => { /* do something here */};
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.