[英]Windows Server 2016 Dockerfile install service
I am attempting to install a service in a docker container on windows server2016.我正在尝试在 windows server2016 上的 docker 容器中安装服务。
Simply placing the service there and Powershelling:只需将服务放在那里和 Powershelling:
New-Service -Name Bob -StartupType Automatic -BinaryPathName .\SVCHost.exe
Adds the service however in the container I get the result:但是在容器中添加服务我得到了结果:
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
I have attempted creating a user and setting the startup user credentials but same issue.我曾尝试创建一个用户并设置启动用户凭据,但同样的问题。
Looking at https://github.com/Microsoft/sql-server-samples/blob/master/samples/manage/windows-containers/mssql-server-2016-express-windows/dockerfile shows that they use sqlexpress to do the install of the service.查看https://github.com/Microsoft/sql-server-samples/blob/master/samples/manage/windows-containers/mssql-server-2016-express-windows/dockerfile表明他们使用 sqlexpress 进行安装的服务。
Long story short... How do I register a service in a Windows server 2016 Docker container长话短说...如何在 Windows Server 2016 Docker 容器中注册服务
Also, look at the Dockerfile for microsoft/iis .另外,请查看microsoft/iis的Dockerfile 。 The real work in the container is done in the IIS Windows Service, but the entrypoint is a binary called
ServiceMonitor.exe
.容器中的实际工作是在 IIS Windows 服务中完成的,但入口点是一个名为
ServiceMonitor.exe
的二进制文件。 The monitor checks the Windows Service, if the Service fails the exe fails, so Docker knows the container is unhealthy.监视器检查 Windows 服务,如果服务失败则 exe 失败,因此 Docker 知道容器不健康。
Fully qualifying the install name works.完全限定安装名称有效。 thanks @Elton Stoneman
谢谢@埃尔顿·斯通曼
or figured out this works too in my program或者在我的程序中发现这也有效
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");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.