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.

  • SQL Server instance string connection in Linux Docker
  • Webpack, core, docker: building webpack with dotnet debug or release build
  • X509CertificateValidationMode not working in Linux?
  • What would prevent code running in a Docker container from connecting to a database on a separate server?
  • Debugging .NET Core projects AND .NET libraries available in NuGet
  • connect .NET API running in linux container with SQL Server running in VM using windows auth
  • Looking for a sample code, reference link etc. which are relevant to dotnet core and not generic info

    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.

  • Return and error code when an app exits in a docker container with aspnetcore
  • Can't connect to Mongo DB in .Net Core api
  • How to disable linux space randomization via dockerfile?
  • Redis Docker - Unable to connect from C# client
  • Starting a barebones MVC C# ASP.NET project in Docker gives “Compilation Error”
  • VS 2017 Add > Docker Support breaks build - “CleanWorkspace” task failed unexpectedly (console app)
  • 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.