You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Windows Server Core 2022 Docker镜像中安装Media Feature Pack失败求助

解决Windows Server Core 2022镜像安装Server-Media-Foundation失败问题

问题背景

项目开发的图像比对功能依赖OpenCV(cv2)库,该库需要系统提供特定图形支持。Windows桌面版默认包含Media Feature Pack,但Jenkins构建代理使用的Windows Server Core 2022镜像未预装此组件,导致本地可正常构建并通过单元测试,而Jenkins构建环境中运行失败。

原Docker构建脚本:

# use the latest Windows Server Core 2022 image.
FROM bd-docker.docker-reg.bddevops.io/dotnet/framework/sdk:4.8-windowsservercore-ltsc2022

SHELL ["powershell", "-command"]
RUN Install-WindowsFeature Server-Media-Foundation

RUN curl -SL --output vs_buildtools.exe https://aka.ms/vs/16/release/vs_buildtools.exe && \
start /w vs_buildtools.exe --quiet --wait --norestart --nocache --add Microsoft.VisualStudio.Workload.MSBuildTools \
del /q vs_buildtools.exe

VOLUME C:\workspace
WORKDIR C:\workspace
ENTRYPOINT ["C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat", "&&", "cmd.exe"]

执行时出现错误:

Install-WindowsFeature : 指定服务器上添加或删除功能的请求失败。
安装一个或多个角色、角色服务或功能失败。
找不到源文件。
请使用"Source"选项指定恢复功能所需文件的位置。有关指定源位置的详细信息...

解决方案

1. 修复Server-Media-Foundation安装的源缺失问题

Windows Server Core镜像默认不包含该功能的安装源文件,必须指定源路径:

方式一:通过Windows Update安装(需构建环境可访问外网)

修改Dockerfile中的安装命令,添加-Source WU参数从Windows Update获取文件:

RUN Install-WindowsFeature Server-Media-Foundation -Source WU

方式二:使用Windows Server 2022安装ISO作为源

如果无法访问外网,将Windows Server 2022的ISO文件放入构建上下文,在Dockerfile中挂载并指定源:

# 复制ISO到镜像临时目录
COPY server2022.iso C:\temp\server2022.iso

RUN Mount-DiskImage -ImagePath "C:\temp\server2022.iso" | Out-Null; \
    $drive = (Get-DiskImage -ImagePath "C:\temp\server2022.iso" | Get-Volume).DriveLetter; \
    Install-WindowsFeature Server-Media-Foundation -Source "$drive`:\\sources\sxs"; \
    Dismount-DiskImage -ImagePath "C:\temp\server2022.iso" | Out-Null; \
    Remove-Item C:\temp\server2022.iso -Force

2. 修复VS Build Tools安装命令的语法错误

原命令中start后缺少分隔符,导致del命令无法执行,修改为:

RUN curl -SL --output vs_buildtools.exe https://aka.ms/vs/16/release/vs_buildtools.exe; \
    start /w vs_buildtools.exe --quiet --wait --norestart --nocache --add Microsoft.VisualStudio.Workload.MSBuildTools; \
    del /q vs_buildtools.exe

3. 修复ENTRYPOINT的语法问题

原ENTRYPOINT路径包含空格且命令格式错误,修改为以下两种方式之一:

方式一:使用cmd执行

ENTRYPOINT ["cmd", "/c", "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat\" && cmd.exe"]

方式二:使用PowerShell执行

ENTRYPOINT ["powershell", "-Command", "& 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat'; cmd.exe"]

内容的提问来源于stack exchange,提问作者Mayank

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 22:55:58