Windows service on docker does not start - windows

I've created a C# WCF Windows service app in VS 2017 and added Docker Support.
The following Dockerfile was created:
FROM microsoft/dotnet-framework:4.7.1-windowsservercore-1709
ARG source
WORKDIR /app
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["C:\\WcfService.exe"]
When I build it using docker-compose in VS I get an error:
Cannot start service from the command line or a debugger. A Windows
Service must first be installed (using installutil.exe) and then
started with the ServerExplorer, Windows Services Administrative tool
or the NET START command. The program '[2172] WcfService.exe' has
exited with code 0 (0x0).
I've opened PowerShell and typed docker ps - the container is running.
So I used New-Service command and to create "TestService".
When I use Get-Service to see all services, I can see it in the list in 'Stopped' mode.
When I use Start-Service TestService I get the following error:
Start-Service : Failed to start service 'TestService (TestService)'.
At line:1 char:1
+ Start-Service TestService
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController)
[Start-Service], ServiceCommandException
+ FullyQualifiedErrorId : StartServiceFailed,Microsoft.PowerShell.Commands.StartServiceCommand
Tried to find info but nothing works. Any ideas?

Ok, so I took Jeroen's advice and dug deeper to see the event viewer. I used some filters on the 'Get-EventLog' command to get the relevant error line and stored it in a variable
$A = Get-EventLog -LogName System -Newest 10 -Source "Service Control Manager" | Select *
Then, I formatted it nice using something like:
$A | Format-List -Property *
and got the exception.
Apparently it has something to do with a C++ dll my app is using. It could be missing or the environment has trouble running it, but that's another issue which I believe I can solve.
Hope that helps others running into similar issues. Thanks.

Related

Launching failed because directory '/remote_debugger' in the container is empty

I have dotnet core 3.1 web api application where I am using Visual Studio 2019 docker and docker-compose tooling feature to run the application.
When I am trying to run the application I am getting below error,
Launching failed because directory '/remote_debugger' in the container is empty. This might be caused by Shared Drives credentials used by Docker Desktop being out of date. Try resetting the credentials in the Shared Drives page of the Docker Desktop Settings and then restart Docker
The build is successful and below is the output. I am seeing some error related to PS script. Is this the reason?
What credential re-setting I need to do, could someone please suggest?
C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -NoProfile -WindowStyle Hidden -ExecutionPolicy RemoteSigned -File "C:\Users\user1\AppData\Local\Temp\GetVsDbg.ps1" -Version vs2017u5 -RuntimeID linux-x64 -InstallPath "C:\Users\user1\vsdbg\vs2017u5"
AuthorizationManager check failed.
+ CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess
C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -NoProfile -WindowStyle Hidden -ExecutionPolicy RemoteSigned -File "C:\Users\user1\AppData\Local\Temp\GetVsDbg.ps1" -Version vs2017u5 -RuntimeID linux-musl-x64 -InstallPath "C:\Users\user1\vsdbg\vs2017u5\linux-musl-x64"
AuthorizationManager check failed.
+ CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess
A non-critical error occurred while getting the container(s) ready. Your project(s) will continue to function normally. The error was: The debugger path 'C:\Users\user1\vsdbg\vs2017u5' for Dockerfile 'C:\Users\user1\source\repos\WebApplication1\WebApplication1\Dockerfile' is invalid.
========== Debugging ==========
docker ps --filter "status=running" --filter "label=com.docker.compose.service" --filter "name=^/WebApplication1$" --format {{.ID}} -n 1
bf37df902db3
In my case, I was using docker desktop with wsl2. And the project I was trying to launch is on net 6.0.
Same popup showed.
I closed the visual studio 22, and started it with administrative privileges, Launched the project. And it worked

Problem with Docker on Windows Server 2019: not running Linux containers

I was trying to install Docker on a fresh Windows Server 2019 using this guide (other guides seem to use the same procedure).
NB: I was given a Windows Server 2019 with Hyper-V installed, but with no virtual machine.
My installation commands were:
Enable-WindowsOptionalFeature –Online -FeatureName Microsoft-Hyper-V –All -NoRestart
Install-WindowsFeature RSAT-Hyper-V-Tools -IncludeAllSubFeature
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Install-Package -Name docker -ProviderName DockerMsftProvider
Restart-Computer –Force
And then:
Get-VM WinContainerHost | Set-VMProcessor -ExposeVirtualizationExtensions $true
Which returns an error:
Get-VM : Hyper-V was unable to find a virtual machine with name "WinContainerHost".
At line:1 char:1
+ Get-VM WinContainerHost | Set-VMProcessor -ExposeVirtualizationExtens ...
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (WinContainerHost:String) [Get-VM], VirtualizationException
+ FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.GetVM
Now, my first question is: what is WinContainerHost? Who did create it? I cannot see it in my Hyper-V Management Console.
Nevertheless, I try to go on with the Docker installation process:
Install-Module DockerProvider
Install-Package Docker -ProviderName DockerProvider -RequiredVersion preview
[Environment]::SetEnvironmentVariable(“LCOW_SUPPORTED”, “1”, “Machine”)
Restart-Service docker
After the process, typing docker --version, I get:
Docker version 17.10.0-ee-preview-3, build 1649af8
It seems that Docker is installed. I then try to launch a container with:
docker pull nginx:latest
which results in:
latest: Pulling from library/nginx
33847f680f63: Extracting [==================================================>] 27.15MB/27.15MB
dbb907d5159d: Download complete
8a268f30c42a: Download complete
b10cf527a02d: Download complete
c90b090c213b: Download complete
1f41b2f2bf94: Download complete
failed to register layer: failed to start service utility VM (applydiff 8f46920b86bdcdab20b89a73c657f59c52f0271fd2fa27bf87bb875c55c11f7a):
container 8f46920b86bdcdab20b89a73c657f59c52f0271fd2fa27bf87bb875c55c11f7a_svm encountered an error during CreateContainer: failure in a
Windows system call: The virtual machine could not be started because a required feature is not installed. (0xc0370102) extra info: {"SystemType"
:"container","Name":"8f46920b86bdcdab20b89a73c657f59c52f0271fd2fa27bf87bb875c55c11f7a_svm","Layers":null,"HvPartition":true,"HvRuntime":{"ImagePath"
:"C:\\Program Files\\Linux Containers","LinuxInitrdFile":"initrd.img","LinuxKernelFile":"bootx64.efi"},"ContainerType":"linux",
"TerminateOnLastHandleClosed":true}
My intuition tells me that the problem is with the Get-VM WinContainerHost | Set-VMProcessor -ExposeVirtualizationExtensions $true, but I cannot find a way to solve it.
Could someone please give me more insight on this? Thanks in advance.

Powershell script for bulk updating Windows Updates on many pc's

I have this script:
Invoke-WUJob -ComputerName comp-1,comp-2,comp-3 -Script {ipmo PSWindowsUpdate; Get-WUInstall -Install -AcceptAll | Out-File C:\PSWindowsUpdate.log } -Confirm:$false -Verbose –RunNow
and after execution I get this:
Invoke-WUJob : PSWindowsUpdate module missing on destination machine
At line:1 char:1
+ Invoke-WUJob -ComputerName 1002-hk-ws-001,1002-hk-ws-002,1002-hk-ws-0 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [Invoke-WUJob], Exception
+ FullyQualifiedErrorId : ModuleMissing,PSWindowsUpdate.InvokeWUJob
I used these commands below on every PC to install to PSWindowsUpdate and setup winrm and it still does not work:
winrm quickconfig -q
winrm set winrm/config/client ‘#{TrustedHosts="comp1,comp2,comp3"}’
Set-ExecutionPolicy RemoteSigned
Install-Module PSWindowsUpdate -Scope CurrentUser -Force
Any ideas?
the windows update cannot use remotely, maybe the hardening, you could work with a schedule task Register-ScheduledJob -scriptblock { get-windowsupdate -acceptall}
I am going to assume that you are in a workgroup mode, vs Domain joined machines by virtue of what you said you did on each host.
You have to be an admin on the target to run this.
about_Remote_Requirements
Unless you make additional configs.
You Don’t Have to Be An Administrator to Run Remote PowerShell Commands
Thus, you need to pass credentials in your code, if you are not already running your PowerShell session with admin creds for the remote targets. This is really PowerShell remoting 101 and a well-documented use case.
Your error is saying the module is not on the remote host or can't be found.
Windows updates are a machine-level thing. So, the import should be to the AllUsers PowerShell profile not some individual user of the machines. There is extra work to get PSRemoting working on workgroup systems. For domain-joined, hosts, you can enable it using GPO. No need for extra steps.
See the steps here:
Enable PowerShell Remoting on a standalone (workgroup) computer
Running code on remote systems will always run in the user context that you started, regardless of who is on the remote target.
Ok so now I'am getting a different error :
Invoke-WUJob : You can not find requested file . (Error HRESULT: 0x80070002)
At line:1 char:1
+ Invoke-WUJob -ComputerName 1002-ski-ws-003,1002-ski-nb-002 -Script {i ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-WUJob], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,PSWindowsUpdate.InvokeWUJob
I've installed everything on remote machines to : Windows\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate but it looks like it still does not see the module ?

Windows 2016: Docker container error

I'm using docker on Windows server 2016, I have created a container using the "microsoft/windowsservercore:latest" image.
On this image i have installed "Print-Server" role but when I try to call "Get-Printer" cmdlet I obtain an error with the spooler service.
These are the commands used to recreate the problem:
docker run -d --name testspoolererror1 microsoft/windowsservercore:latest ping -t localhost
docker exec -it testspoolererror1 powershell
Install-WindowsFeature Print-Server
Set-Service spooler -StartupType Automatic
Start-Service spooler
Get-Service spooler
Get-Printer
This is when I receive the error:
Get-Printer : The spooler service is not reachable. Ensure the spooler service is running.
At line:1 char:1
+ Get-Printer
+ ~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (MSFT_Printer:ROOT/StandardCimv2/MSFT_Printer) [Get-Printer], CimException
+ FullyQualifiedErrorId : HRESULT 0x800706ba,Get-Printer
In the event viewer i found the error:
The Print Spooler service terminated unexpectedly. It has done this 2 time(s).
Can Anyone help me to solve this problem?
Because Windows containers are sharing same kernel with host machine you cannot have spooler running on both same time. So stop and disable spooler from host and you are able use spooler on one container on that server.
Here is fixed set of commands:
Stop-Service spooler
Set-Service spooler -StartupType Disabled
docker run -d --name testspoolererror1 microsoft/windowsservercore:latest ping -t localhost
docker exec -it testspoolererror1 powershell
Install-WindowsFeature Print-Server
Set-Service spooler -StartupType Automatic
Start-Service spooler
Get-Service spooler
Get-Printer
I'm sorry to hear you're having this issue and I'll be glad to do what I can to help you sort it out :)
For the sake of being thorough, I tried this myself by running the following commands:
docker run -it microsoft/windowsservercore:latest powershell
(Now running powershell from within container)
Install-WindowsFeature Print-Server
Set-Service spooler -StartupType Automatic
Start-Service spooler
Get-Service spooler
Get-Printer
I was able to run these on my system, without an error. So that's a start.
Now, from your error it looks like the spooler service didn't even start. What do you see when you run Get-Service spooler? Will you try running these commands on your system just as I have listed them above then report back with your results?
Also, to clarify, what are you trying to do when you're pinging localhost from the container? Are you trying to ping your container host?
And as a side note, if you're looking for background info on how container networking works on Windows, here's a good place to start: https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/container-networking
--Kallie B. (Program Manager, Microsoft Networking Team)
The reason that Kallie seems to have been able to get the above steps to work is probably because it is being hosted differently. I tried the above steps via Docker on a Server 2016 box, and hit the same errors. When I tried it via Docker on Windows 10, I was able to launch the spooler successfully and run the above commands, but I couldn't install any drivers successfully which would make it actually useful. Pnputil just throws odd "No Data" errors when attempting to install any .inf's.
My guess is that it works on Windows 10 because it's using hyper-v emulation instead of the native container used when hosting Server 2016 Core on Server 2016. Another thing I noticed was that the drivers are inherited from the base machine when creating a container on Server 2016, but not on Windows 10. I assume that's fairly well-understood behavior by Docker experts, but it does seem like the inherited drivers might be causing the crash. I'm not a Windows expert either, though.
Either way, it seems like something that Microsoft will have to look into and resolve.
The network that docker runs on (by default) is not that same network as the host.
Pinging localhost from inside the container is not doing what you think it's doing.
Learn how docker networks as step 1.

Can not see my service under services after installing with Topshelf

I am pretty sure the answer is so simple but here it is;
I'm using TopShelf to install my service and I can succesfully install and run it from command line as
MyExecutable.Daemon install
MyExecutable.Daemon start
This is fine but it has to be amongst the Services and it wasn't so I tried;
sc create "MyExecutable.Daemon" binPath= "C:\'Program Files (x86)'\MyExecutable.Daemon.exe" DisplayName= "MyExecutable.Daemon" start= auto
but got
Set-Content : A positional parameter cannot be found that accepts argument 'binpath='.
At line:1 char:1
+ sc create MyExecutable.Daemon binpath= "C:\'Program Files (x86)'\...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-Content], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetContentCommand
So I'm stuck here. What am I missing here?
sc in powershell is the alias for set-Content cmdlet use sc.exe instead.
Try this (not tested)
sc.exe create "MyExecutable.Daemon" binPath="C:\'Program Files (x86)'\MyExecutable.Daemon.exe" DisplayName="MyExecutable.Daemon" start=auto
You should do MyExecutable.Daemon install start. I think I've done that successfully from a PowerShell prompt before but I guess I would have to verify. If that doesn't work, you need to enable logging with one of the logging plugins and provide the log file. You shouldn't use sc to install a Topshelf service. That will fail.

Resources