简体   繁体   English

Windows Server 2016 Dockerfile 安装服务

[英]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/iisDockerfile 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.

相关问题 尝试使用 Install-Module 在 Windows Server 2016 中安装 Docker 时出错 - Error trying to install Docker in Windows Server 2016 with Install-Module 无法以管理员身份在新安装的 Windows Server 2016 上安装 NuGet? - Unable to Install NuGet on newly installed Windows Server 2016 as Administrator? 使用提升的 PowerShell 在 Windows Server 2016 上安装 Docker Engine Enterprise 失败 - Install Docker Engine Enterprise on Windows Server 2016 fails using elevated PowerShell 安装/卸载Windows服务 - install/uninstall a Windows Service Windows Server 2016 密码套件不起作用 - Windows Server 2016 Cipher Suites not working AWS 创建 Windows 服务器 2016 并安装软件 - AWS creating a Windows server 2016 with software installation 在 Windows 2016 服务器上使用 Powershell ServerManager 模块 - Using Powershell ServerManager module on Windows 2016 Server Ansible 无法在 Windows 中安装 Microsoft Office 2016 10 - Ansible cant install Microsoft Office 2016 in Windows 10 AWS Cloudformation Windows 2016 EC2 S3 静默安装 - AWS Cloudformation Windows 2016 EC2 S3 silent install 使用厨师配方禁用 Windows Server 2016 上的服务器管理器 - disable server manager on Windows Server 2016 with chef recipe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM