Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do gracefully shutdown on dotnet with docker?

Tags:

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.

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.

like image 873
cilerler Avatar asked Nov 22 '16 12:11

cilerler


People also ask

How do you gracefully stop a docker container?

docker rm -f The final option for stopping a running container is to use the --force or -f flag in conjunction with the docker rm command. Typically, docker rm is used to remove an already stopped container, but the use of the -f flag will cause it to first issue a SIGKILL.

What is Docker dotnet?

NET Core Docker images are published to the Microsoft Container Registry (MCR) and are discoverable at the Microsoft . NET Core Docker Hub repository. Each repository contains images for different combinations of the . NET (SDK or Runtime) and OS that you can use.


1 Answers

In .NET Core 2.0, you can use the AppDomain.CurrentDomain.ProcessExit event, which works fine on Linux in Docker. AssemblyLoadContext.Default.Unloading probably works as well, even before .NET Core 2.0.

like image 191
Marc Sigrist Avatar answered Sep 23 '22 05:09

Marc Sigrist