Windows Server 2016 Dockerfile安装服务

我正在尝试在Windows Server2016上的Docker容器中安装服务。

简单地把服务放在那里和Powershelling:

New-Service -Name Bob -StartupType Automatic -BinaryPathName .\SVCHost.exe 

然后在容器中添加服务我得到结果:

 PS C:\Program Files\COMPANY\Repository> start-service -Name bob start-service : Service 'bob (Bob)' cannot be started due to the following error: Cannot start service Bob on computer '.'. At line:1 char:1 + start-service -Name bob + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service], ServiceCommandException 

我试图创build一个用户,并设置启动用户凭据,但同样的问题。

看着https://github.com/Microsoft/sql-server-samples/blob/master/samples/manage/windows-containers/mssql-server-2016-express-windows/dockerfile显示他们使用sqlexpress做安装的服务。

长话短说…如何在Windows Server 2016 Docker容器中注册服务

另外,请查看适用于Microsoft / iis的Dockerfile 。 容器中的实际工作是在IIS Windows服务中完成的,但入口点是一个名为ServiceMonitor.exe的二进制文件。 监视器检查Windows服务,如果服务失败,exe文件失败,所以Docker知道容器是不健康的。

完全限定安装名称的作品。 谢谢@Elton Stoneman

或者在我的程序中也发现了这个问题

  public static bool Install(string serviceName, string serviceDescription, string logonUsername, string logonPassword, string exeFile) { string managementPath = @"\\.\ROOT\CIMV2:Win32_Service"; ManagementClass mc = new ManagementClass(managementPath); ManagementBaseObject inParams = mc.GetMethodParameters("create"); inParams["Name"] = serviceName; inParams["DisplayName"] = serviceDescription; inParams["PathName"] = exeFile + " -name " + "\"" + serviceName + "\""; inParams["ServiceType"] = ServiceType.Win32OwnProcess; inParams["ErrorControl"] = 0; inParams["StartMode"] = ServiceStartMode.Automatic; inParams["DesktopInteract"] = false; inParams["StartName"] = logonUsername; inParams["StartPassword"] = logonPassword; inParams["LoadOrderGroup"] = null; inParams["LoadOrderGroupDependencies"] = null; inParams["ServiceDependencies"] = null; ManagementBaseObject outParams = mc.InvokeMethod("create", inParams, null); string status = outParams["ReturnValue"].ToString(); return (status == "0" || status == "23"); }