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.

  • Two docker nodes running .NET Services, talking to each other
  • dotnet docker /bin/sh: 1: [dotnet,: not found
  • SQL Server instance string connection in Linux Docker
  • How do I proxy every request from a dotnet core app running in a docker container
  • Create long running .NET Core service targeting Linux Docker container
  • .NET Core 1.1, Docker Build encounters Couldn't find 'project.json' with csproj
  • 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.

  • Cannot connect Npgsql to Postgres DB running on Docker
  • How can I create a stream for DockerDotNet BuildImageFromDockerfile method?
  • Docker Compose not starting mongo service even main service depends on it
  • GDB problems inside docker
  • Can't restart a docker container that was created and worked via visual studio 2015's build
  • Does Mono support SqlDbType Structured?
  • 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.