首页 > 解决方案 > .Net Core Windows 服务未安装在 docker 容器中

问题描述

我面临一个非常特殊的问题。我有一个 .net 核心 Windows 服务 (XYZ),其安装程序 (XYZ.msi) 是使用 Wix 创建的。我正在尝试将此服务安装在容器中。该服务已安装,然后 Windows 尝试将其注册为服务,该服务超时,在 System Eventlogs 中向我提供以下“信息” The XYZ Service (XYZ) service failed to start due to the following error: %%1053 A timeout was reached (30000 milliseconds) while waiting for the XYZ service (XYZ) service to connect.,然后该服务被卸载,这是预期的。

此外,当我检查应用程序事件日志时,我得到了这些

Product: XYZ -- Error 1920. Service 'XYZ' (XYZ) failed to start. Verify that you have sufficient privileges to start system services.

Windows Installer installed the product. Product Name: XYZ. Product Version: 0.0.0.0. Product Language: 1033. Manufacturer: .... Installation success or error status: 1603.

因此,为了理解这些错误代码,我参考了错误代码 1603和错误 1920 上的一些其他链接,但由于这些非常通用,这些链接没有用。

相同的服务在本地和不同的服务器上运行良好。

XYZ.msi 所在的容器内的文件夹具有这些权限

Path   : Microsoft.PowerShell.Core\FileSystem::C:\app
Owner  : NT AUTHORITY\SYSTEM
Group  : NT AUTHORITY\SYSTEM
Access : BUILTIN\Administrators Allow  FullControl
         BUILTIN\Administrators Allow  268435456
         NT AUTHORITY\SYSTEM Allow  FullControl
         NT AUTHORITY\SYSTEM Allow  268435456
         NT AUTHORITY\Authenticated Users Allow  Modify, Synchronize
         NT AUTHORITY\Authenticated Users Allow  -536805376
         BUILTIN\Users Allow  ReadAndExecute, Synchronize
         BUILTIN\Users Allow  -1610612736
Audit  :
Sddl   : O:SYG:SYD:(A;ID;FA;;;BA)(A;OICIIOID;GA;;;BA)(A;ID;FA;;;SY)(A;OICIIOID;GA;;;SY)(A;ID;0x1301bf;;;AU)(A;OICIIOID;SDGXGWGR;;;AU)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)

此外,我假设所有安装都使用容器内的 ContainerAdministrator 帐户进行。

现在我无法弄清楚问题是什么,如何进一步排除故障,以及如果它的权限问题,我需要设置哪些权限。在这方面的任何帮助将不胜感激。谢谢 !

编辑: dockerFile 看起来像这样

FROM mcr.microsoft.com/windows/servercore:ltsc2019-amd64
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
WORKDIR /app
COPY [".","."]
RUN  ["powershell.exe", "./install.cmd"]

WiX .wxs 代码

<Fragment>
    <ComponentGroup Id="ServiceComponents" Directory="APPLICATIONFOLDER">
      <Component Id="ServiceComponent" Guid="649E5964-126A-4DF5-95CF-CE7C2474E981">
        <File Id="xyz.exe" KeyPath="yes" Vital="yes" DiskId="1" Source="..\xyz\bin\$(var.Platform)\$(var.Configuration)\netcoreapp3.1\win-x64\xyz.exe"/>
        <ServiceInstall
          Id="ServiceInstaller"
          Type="ownProcess"
          Vital="yes"
          Name="xyz"
          DisplayName="$(var.ProductName)"
          Description="$(var.Description)"
          Start="auto"
          Account="NT AUTHORITY\LocalService"
          ErrorControl="normal" Interactive="no">
          <ServiceConfig DelayedAutoStart="yes" OnInstall="yes" OnReinstall="yes" />
          <util:ServiceConfig FirstFailureActionType="restart" SecondFailureActionType="restart" ThirdFailureActionType="none" ResetPeriodInDays="1" RestartServiceDelayInSeconds="0" />
        </ServiceInstall>
        <ServiceControl
          Id="ServiceController"
          Name="xyz"
          Start="install"
          Stop="both"
          Remove="both"
          Wait="yes" />
      </Component>
    </ComponentGroup>
  </Fragment>

标签: docker.net-corewixuser-permissions

解决方案


我个人从未尝试在容器内安装 MSI。我使用过的容器(主要是基于 linux 的)容器 simple 会将 EXE 称为控制台应用程序,而且它实际上并不是一个服务。我会根据您所写的内容假设可以在 Windows 容器内安装 MSI。

话虽如此,1920 错误只是意味着服务没有启动。“验证您是否拥有管理员”一直是用词不当。要在 Windows 中进行故障排除,我通常会在此处暂停安装程序并尝试手动运行 EXE 以查看控制台是否出现任何错误。通常,这将是一条消息,说明 .NET (Core) 或未安装某些依赖项。如果 EXE 实际启动并且您在路上遇到了一些异常,那么这将需要额外的调试。

我不确定你是如何劫持 Windows 容器的,但你需要做一些类似于调试/分析问题的事情。基本上它适用于一台机器而不是您的容器,因为您的 docker 映像没有另一台机器所具有的东西,而且您的代码不喜欢它。


推荐阅读