如何使用docker在dotnet上正常关闭? [英] How to do gracefully shutdown on dotnet with docker?

查看:107
本文介绍了如何使用docker在dotnet上正常关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以正常关闭在 DOCKER 中运行的 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 I would like to pass my cancellation token/s to current methods and postpone the shut-down while they are working.

查找与dotnet核心相关但与通用信息无关的示例代码,参考链接等

Looking for a sample code, reference link etc. which are relevant to dotnet core and not generic info


更新
这个问题不是即使在.net核心控制台应用程序中使用Console.ReadLine(),docker容器也会立即退出,因为我没有立即退出的问题。我需要使用类似 Windows.SystemsEvents.SessionEnding的事件并依靠 Console.CancelKeyPress 和/或实现 WebHostBuilder()并不适合。

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.


推荐答案

在.NET Core 2.0中,您可以使用 AppDomain .CurrentDomain.ProcessExit 事件,在Docker中的Linux上运行正常。 AssemblyLoadContext.Default.Unloading 可能也可以工作,甚至在.NET Core 2.0之前。

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.

这篇关于如何使用docker在dotnet上正常关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆