Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install Server-Media-foundation in Windows Server core #159

Closed
arjaiswa opened this issue Sep 22, 2021 · 22 comments
Closed

Install Server-Media-foundation in Windows Server core #159

arjaiswa opened this issue Sep 22, 2021 · 22 comments
Assignees

Comments

@arjaiswa
Copy link

HI Team,
We are doing UI testing in the firefox browser and for the same, I am using this base image mcr.microsoft.com/windows/servercore:ltsc2019 as per size consideration.

But while launching the browser I am getting errors:
browserType.launch: The host system is missing dependencies!

Some of the Media Foundation files cannot be found on the system. If you are
on Windows Server try fixing this by running the following command in PowerShell
as Administrator:

    Install-WindowsFeature Server-Media-Foundation

We tried to install this feature but I can see the Windows feature is in a removed state
image

Could you please provide any way to install this in windows server core?

@ghost ghost added the triage New and needs attention label Sep 22, 2021
@naikrovek
Copy link

naikrovek commented Sep 24, 2021

I'm taking a guess here, but you may need to create a custom image using mcr.microsoft.com/windows/servercore:ltsc2019 as a base. in your Dockerfile, RUN powershell.exe Install-WindowsFeature Server-Media-Foundation and specify your ENTRYPOINT and expose your ports as normal.

That should get you going, if I am understanding things properly.

Why is this necessary? You are not able to modify the container as provided by Microsoft, meaning that you can't install OS features into Microsoft's container. Therefore, you must create your own container (which itself is a small layer on top of that image with the changes that you wish to make) and use that container instead. This is one of the very core features of Docker, and it is a strength of container images; you can trust that the container from Microsoft is set up properly and that you can't mess it up.

@arjaiswa
Copy link
Author

Hi Johnson,
You are correct, I am creating a custom image in which I am using windows base image
Below is the docker file I am using
FROM mcr.microsoft.com/windows/servercore:ltsc2019

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

ENV NODE_VERSION 12.4.0

RUN Invoke-WebRequest $('https://nodejs.org/dist/v{0}/node-v{0}-win-x64.zip' -f $env:NODE_VERSION) -OutFile 'node.zip' -UseBasicParsing ;
Expand-Archive node.zip -DestinationPath C:\ ;
Rename-Item -Path $('C:\node-v{0}-win-x64' -f $env:NODE_VERSION) -NewName 'C:\nodejs'

USER ContainerAdministrator
RUN [Environment]::SetEnvironmentVariable('Path', $env:Path + ';C:\nodejs', 'Machine')

RUN Install-WindowsFeature Server-Media-Foundation

WORKDIR /usr/src/app
COPY . .

RUN npm install

ENV PORT 8090

CMD ["node", "index.js" ]

At the Install windows feature line, I am getting an error that the source is not available.

@naikrovek
Copy link

This may help. It describes your problem and how to obtain the bits necessary to get the feature installed.

@judyliu-ms judyliu-ms self-assigned this Oct 20, 2021
@judyliu-ms judyliu-ms added Image composition and removed triage New and needs attention labels Oct 20, 2021
@tobrien-bit
Copy link

tobrien-bit commented Oct 25, 2021

It seems that sources are missing so it is not straightforward.

Sending build context to Docker daemon  44.03kB
Step 1/3 : FROM mcr.microsoft.com/windows/servercore:ltsc2022
 ---> 801c33f5de3a
Step 2/3 : RUN powershell.exe "Install-WindowsFeature Server-Media-Foundation"
 ---> Running in 60fa8d019b33
Install-WindowsFeature : The request to add or remove features on the
specified server failed.
Installation of one or more roles, role services, or features failed.
The source files could not be found.
Use the "Source" option to specify the location of the files that are required
to restore the feature. For more information on specifying a source location,
see https://go.microsoft.com/fwlink/?LinkId=243077. Error: 0x800f081f
At line:1 char:1
+ Install-WindowsFeature Server-Media-Foundation
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (@{Vhd=; Credent...Name=localh
   ost}:PSObject) [Install-WindowsFeature], Exception
    + FullyQualifiedErrorId : DISMAPI_Error__Failed_To_Enable_Updates,Microsof
   t.Windows.ServerManager.Commands.AddWindowsFeatureCommand

Success Restart Needed Exit Code      Feature Result
------- -------------- ---------      --------------
False   No             Failed         {}


The command 'cmd /S /C powershell.exe "Install-WindowsFeature Server-Media-Foundation"' returned a non-zero code: 1

@naikrovek
Copy link

naikrovek commented Oct 25, 2021

you can get the sources it is looking for from the appropriate Windows Server install media, then tell dism.exe where to find them. I assume the same is possible with the PowerShell command.

@tobrien-bit
Copy link

you can get the sources it is looking for from the appropriate Windows Server install media, then tell dism.exe where to find them. I assume the same is possible with the PowerShell command.

Yeah, just annoying having to keep sources accessible in a CI pipeline.

@ghost
Copy link

ghost commented Nov 26, 2021

This issue has been open for 30 days with no updates.
@judyliu-ms, please provide an update or close this issue.

@judyliu-ms
Copy link

We have added this to our backlog, for internal ADO tracking: Scenario #37316033

@ghost
Copy link

ghost commented Jan 9, 2022

This issue has been open for 30 days with no updates.
@judyliu-ms, please provide an update or close this issue.

1 similar comment
@ghost
Copy link

ghost commented Feb 8, 2022

This issue has been open for 30 days with no updates.
@judyliu-ms, please provide an update or close this issue.

@michbern-ms
Copy link
Contributor

michbern-ms commented Feb 19, 2022

I wanted to document a straightforward way of getting Server Media Foundation installed on ServerCore for Windows Server 2022. This isn’t exceptionally clever, but it does work.

First, you’ll need an up-to-date Windows Server 2022 machine to serve as a source of repair media. This article covers the topic in some depth, but to summarize: in order to keep Server Core images small, we removed a number of less-commonly used features. (Roles, Role Services, and Features not in Server Core containers - Windows Server, version 1803 | Microsoft Docs) Putting those features back requires up-to-date install/repair media. There are a few ways to accomplish this, but the simplest is just to take a Windows Server 2022 VM and let Windows Update bring it up to date.

I found it easiest to use this same Server 2022 VM as the container host, but you don't have to do it that way.
From the Server 2022 VM, you’ll also need to share out the %windir%\WinSxS directory. I created a local user with a randomly-generated password for this:

net user ShareUser <password> /ADD
net share WinSxS=%windir%\WinSxS /grant:ShareUser,READ

I created a simple script to do the feature installation and called it InstallSMF.cmd:

REM Connect to the WinSxS share on the container host
for /f "tokens=3 delims=: " %%g in ('netsh interface ip show address ^| findstr /c:"Default Gateway"') do set GATEWAY=%%g
net use o: \\%GATEWAY%\WinSxS /user:ShareUser %SHARE_PW%
if errorlevel 1 goto :eof
 
REM Install the ServerMediaFoundation feature
dism /online /enable-feature /featurename:ServerMediaFoundation /Source:O:\ /LimitAccess

And then used the following Dockerfile:

FROM mcr.microsoft.com/windows/servercore:ltsc2022
ARG SHARE_PW=
WORKDIR /install
COPY InstallSMF.cmd .
RUN InstallSMF.cmd

And built as:

docker build –build-arg SHARE_PW=<password> .

Yes, you will end up with the SHARE_PW in the build trace, but since I set it up as a randomly-generated string for each build, I’m not leaking a real secret.

The end of my Docker build looks like:

[===========================98.9%========================= ]
[==========================100.0%==========================]
The operation completed successfully.
Removing intermediate container 45b91e34fe3b
---> 3026d3a45a00
Successfully built 3026d3a45a00

I cleaned up with:

net share WinSxS /delete
net user ShareUser /delete

@nirbheek
Copy link

nirbheek commented Feb 23, 2022

@michbern-ms Those steps worked for me, thanks! I had to make two changes:

-net use o: [\\%GATEWAY%\WinSxS](file://%25gateway%25/WinSxS) /user:ShareUser %SHARE_PW%
+net use o: \\%GATEWAY%\WinSxS /user:ShareUser %SHARE_PW%
-COPY InstallSMF.cmd .
-RUN InstallSMF.cmd
+COPY InstallSMF.cmd C:\TEMP
+RUN C:\TEMP\InstallSMF.cmd

But mfcore.dll seems to need ksuser.dll which is still missing from the image, so Media Foundation doesn't entirely work. What component provides that? Unrelatedly, I also need dsound.dll, do you know which component provides that? I've hunted for hours on the internet and found only noise / spam about both these.

@michbern-ms
Copy link
Contributor

michbern-ms commented Feb 23, 2022

@nirbheek Thanks for the corrections! I pasted from a rich text app and it did something funny with the file link. I went back and fixed it in the original comment above.

Can you double check on ksuser? My image built with the Dockerfile does have it:

C:\Windows>dir /s ksuser.dll
 Volume in drive C has no label.
 Volume Serial Number is 6CAA-C056

 Directory of C:\Windows\System32

05/08/2021  12:11 AM            45,792 ksuser.dll
               1 File(s)         45,792 bytes

 Directory of C:\Windows\SysWOW64

05/08/2021  12:12 AM            20,632 ksuser.dll
               1 File(s)         20,632 bytes

I'll see what I can find out about dsound.dll and get back to this thread.

@michbern-ms
Copy link
Contributor

@nirbheek About dsound.dll - that one turns out to be part of the ServerCore App Compatibility FoD (https://docs.microsoft.com/en-us/windows-server/get-started/server-core-app-compatibility-feature-on-demand)

That FoD basically does ServerCore -> Server. It doesn't make sense to install the FoD in that case; just use the Server image (https://hub.docker.com/_/microsoft-windows-server/) I recognize that using Server is a big size increase just to get dsound.dll, but that's the answer to your question in terms of the official path to get that DLL.

@nirbheek
Copy link

@michbern-ms I realized I was using ltsc2019 and not ltsc2022, maybe that's why ksuser.dll was not available?

Thanks for finding out about dsound.dll for me! Maybe we'll do something hacky if that turns out to be too expensive.

@cwilhit
Copy link
Contributor

cwilhit commented Feb 24, 2022

Closing this issue given @michbern-ms has answered and provided a solution.

@yavuzsonmez
Copy link

I wanted to document a straightforward way of getting Server Media Foundation installed on ServerCore for Windows Server 2022. This isn’t exceptionally clever, but it does work.

First, you’ll need an up-to-date Windows Server 2022 machine to serve as a source of repair media. This article covers the topic in some depth, but to summarize: in order to keep Server Core images small, we removed a number of less-commonly used features. (Roles, Role Services, and Features not in Server Core containers - Windows Server, version 1803 | Microsoft Docs) Putting those features back requires up-to-date install/repair media. There are a few ways to accomplish this, but the simplest is just to take a Windows Server 2022 VM and let Windows Update bring it up to date.

I found it easiest to use this same Server 2022 VM as the container host, but you don't have to do it that way. From the Server 2022 VM, you’ll also need to share out the %windir%\WinSxS directory. I created a local user with a randomly-generated password for this:

net user ShareUser <password> /ADD
net share WinSxS=%windir%\WinSxS /grant:ShareUser,READ

I created a simple script to do the feature installation and called it InstallSMF.cmd:

REM Connect to the WinSxS share on the container host
for /f "tokens=3 delims=: " %%g in ('netsh interface ip show address ^| findstr /c:"Default Gateway"') do set GATEWAY=%%g
net use o: \\%GATEWAY%\WinSxS /user:ShareUser %SHARE_PW%
if errorlevel 1 goto :eof
 
REM Install the ServerMediaFoundation feature
dism /online /enable-feature /featurename:ServerMediaFoundation /Source:O:\ /LimitAccess

And then used the following Dockerfile:

FROM mcr.microsoft.com/windows/servercore:ltsc2022
ARG SHARE_PW=
WORKDIR /install
COPY InstallSMF.cmd .
RUN InstallSMF.cmd

And built as:

docker build –build-arg SHARE_PW=<password> .

Yes, you will end up with the SHARE_PW in the build trace, but since I set it up as a randomly-generated string for each build, I’m not leaking a real secret.

The end of my Docker build looks like:

[===========================98.9%========================= ]
[==========================100.0%==========================]
The operation completed successfully.
Removing intermediate container 45b91e34fe3b
---> 3026d3a45a00
Successfully built 3026d3a45a00

I cleaned up with:

net share WinSxS /delete
net user ShareUser /delete

Hi,

seems like the fix doesn't work anymore. I get the following error:

Install-WindowsFeature : The request to add or remove features on the
specified server failed.
Installation of one or more roles, role services, or features failed.
The source files could not be found.

@michbern-ms
Copy link
Contributor

@yavuzsonmez Sorry to hear you are having trouble. Please make sure your Server 2022 host machine is fully patched, and that you are using a current Server 2022 container image as well.

I re-ran this process this morning with the latest Server 2022 updates (from October 10, 2023) and it worked as expected.

The error you are seeing suggests that the optional component inside the container is looking for source files from the Source media, but cannot find them. In my experience, this always happens when the machine providing the Source media is not up to date.

@madduci
Copy link

madduci commented Dec 4, 2023

I'm having the same issue on Windows Core Server 2019 containers with .NET 4.8 as base image.

I don't have physical access to a Windows 2019 server, since i use ephemeral VMs to create the docker images. Is there any other way to get the required sources, maybe through Microsoft website? I find the solution for the issue for me not really possible.

The output of the command Install-WindowsFeature Server-Media-Foundation is

Install-WindowsFeature : The request to add or remove features on the specified server failed.
Installation of one or more roles, role services, or features failed.
The source files could not be found.
Use the "Source" option to specify the location of the files that are required to restore the feature. For more information on specifying a source location, see
http://go.microsoft.com/fwlink/?LinkId=243077. Error: 0x800f081f
At line:1 char:1
+ Install-WindowsFeature Server-Media-Foundation
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (@{Vhd=; Credent...Name=localhost}:PSObject) [Install-WindowsFeature], Exception
    + FullyQualifiedErrorId : DISMAPI_Error__Failed_To_Enable_Updates,Microsoft.Windows.ServerManager.Commands.AddWindowsFeatureCommand

Success Restart Needed Exit Code      Feature Result
------- -------------- ---------      --------------
False   No             Failed         {}

@noamshvacher
Copy link

noamshvacher commented Feb 22, 2024

Hi @michbern-ms !
do I have to use windows server 2022 as a host?
I am using my personal laptop windows 11 Pro latest.
But unfortunately it seems that Server-Media-Foundation feature is not available for regular windows 11 pro

@michbern-ms
Copy link
Contributor

@noamshvacher You do need a Windows Server 2022 image, fully patched -- but it doesn't have to be the host. The heart of the technique is that Windows is going to restore the removed feature into the Windows Server 2022 Server Core container - and it needs the Windows Server 2022 image as a source to get the component files from. But you do not have to be running from it. You just need access to the file system.

@noamshvacher
Copy link

@michbern-ms I will try that, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants