Windows 2016: Docker container error - windows

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.

Related

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.

My windows service in the image can't auto start when I start the container

Please help me,
I have built an image windows server with a windows service inside from the dotnet-framework-docker as a base image.
I have set (-StartupType Automatic) to that service, but when the container is online, the service doesn't start.
Here is the command in Dockerfile
New-Service -Name $service_name -DisplayName $service_display_name -Description 'Domain Handlers' -BinaryPathName $service_path -StartupType Automatic
and here is the status of that service I got from the running container.
ExitCode : 0
Name : Project-Dev
ProcessId : 0
StartMode : Auto
State : Stopped
Status : OK
I also have two solutions for now.
First, I think I can make a script and set it runs in ENDTRYPOINT or CMD, that script will start the service when the container is online.
Second, I saw that the service is running under local system permission and have heard about LocalService and NetworkService, so the question is if my service runs under Local service or network service, then It can auto start? (I thought about the permission, maybe the service can't start because of the permission)
So, please help me to get out of this stuff
I have fixed the issue by created an onboot.service.ps1 script and set it on the ENTRYPOINT in the Dockerfile.
ENTRYPOINT ["powershell.exe", "C:\\Docker_onboot.services.ps1"]
The contents in that script are:
Start-Service -Name 'ServiceName'
I'm running the container inside Amazone ECS.
Hope this helpful

Windows service on docker does not start

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.

failing to start docker engine open //./pipe/docker_engine

I'm receiving the following error in docker on windows 10 laptop.
I've try to reinstall and restart but nothing helps.
The docker service is running OK but what i understand that i have a problem with the docker daemon (from what i read)
The whole issue started when i run the 2 commands:
net stop com.docker.service
net start com.docker.service
from there on i keep getting the error below and cannot solve it.
C:\Users\xxxx>docker images error during connect: Get
http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.30/images/json: open
//./pipe/docker_engine: The system cannot find the file specified. In
the default daemon configuration on Windows, the docker client must be
run elevated to connect. This error may also indicate that the docker
daemon is not running.
anyone succeed to solve it?
docker client must be run elevated to connect
This indicates that you do not have enough permissions. Try starting the terminal as administrator.
I run Docker remotely as a non admin user.
For this the user running docker should have full permission to location where Docker is installed.
User should be part of docker_users group
docker daemon runs on port 2375 by default. Try to whitelist this port. Allow incoming connections to 2375 in Windows Firewall settings
Restart your docker daemon and Docker service.
Restart the running Docker instance[Docker for Windows] if required. You do not have to reinstall.

how to check wds service is running or not

Can I please know how to check WDS service is running or not?
After patching, WDS service is disabled. Server asked for a reboot to start WDS. Can I know how to check WDS is running or not?
First solution:
Go to the services page (Windows Key + R > type services.msc)
Search for Windows Deployment Services Server
Check if the status is Running
Second solution:
Start the commandline: Windows Key + R > CMD
Type net start
Check if Windows Deployment Services Server is listed
Programmatically in PowerShell,
(Get-Service -Name "WDSServer").Status
To do the same remotely,
(Get-Service -ComputerName <computer name> -Name "WDSServer").Status

Resources