How to tap into shut-down event from DOTNET-CORE?

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 (clicking on Kitematic’s stop button, docker stop ... etc.) 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