【问题标题】:Docker: Running Windows Console application - Failed to create system events window threadDocker:运行 Windows 控制台应用程序 - 无法创建系统事件窗口线程
【发布时间】:2021-06-15 17:03:38
【问题描述】:

我正在尝试在容器中运行 Windows 控制台应用程序(.net 核心)。它在主机上运行良好,但是一旦我运行 docker 容器,它就会抛出这个 error

The type initializer for 'MyApp.Utility.SystemEventsHandler' threw an exception.
 ---> System.Runtime.InteropServices.ExternalException (0x80004005): Failed to create system events window thread.
   at Microsoft.Win32.SystemEvents.EnsureSystemEvents(Boolean requireHandle)
   at Microsoft.Win32.SystemEvents.add_SessionEnding(SessionEndingEventHandler value)

Docker 文件

# getting base image 
FROM mcr.microsoft.com/dotnet/runtime:3.1

#  copy files 
COPY app/ app/

# set working directory
WORKDIR app

# entry point
#ENTRYPOINT ["dotnet","MyApp.dll"] 

我还需要在容器中安装其他东西吗?

【问题讨论】:

  • 您可能正在使用 linux 容器,然后尝试访问 windows 特定的 API,这在 linux 环境中当然不会工作。
  • @Henkolicious,我在 Windows 上运行它。

标签: docker .net-core containers console-application


【解决方案1】:

问题不在于您使用 docker 在 Windows 操作系统主机上运行控制台应用程序。问题是您正在运行一个 linux 容器(非常精简的 linux 操作系统版本),然后尝试访问特定于 windows 的 API。

正如错误状态Failed to create system events window thread. at Microsoft.Win32.SystemEvents...

这就是为什么当您在 Windows 操作系统主机上调试应用程序时,应用程序工作得很好,但在 linux 容器中却不行。例如,如果将其部署到常规 linux 主机或尝试在 WSL 中运行,您将获得相同的效果。

可能有用的一件事是切换到windows container,但我不知道您的代码看起来如何。要切换到 Windows 容器,我认为您只需右键单击 docker 桌面的系统托盘图标并交换即可。不过我没用过windows容器,所以不知道。

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images?view=aspnetcore-5.0#run-in-a-windows-container

PS 我希望您不要尝试在 docker 中运行 GUI 应用程序,这是不受支持的。

【讨论】:

  • 这是不正确的。我在 Windows 容器中运行我的应用程序。
猜你喜欢
  • 2010-11-19
  • 1970-01-01
  • 1970-01-01
  • 2011-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-04
  • 1970-01-01
相关资源
最近更新 更多