【发布时间】:2020-05-08 13:00:52
【问题描述】:
stackoverflow 的同胞们!
我最近在尝试创建运行 IIS 的 Windows 容器时遇到了问题。目前,我的 dockerfile 如下所示
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.7.2-windowsservercore-ltsc2016
# Install Powershell
ADD https://github.com/PowerShell/PowerShell/releases/download/v7.0.0/PowerShell-7.0.0-win-x64.zip c:/powershell.zip
RUN powershell.exe -Command Expand-Archive c:/powershell.zip c:/PS7 ; Remove-Item c:/powershell.zip
RUN C:/PS7/pwsh.EXE -Command C:/PS7/Install-PowerShellRemoting.ps1
# Update shell to powershell (PS7)
SHELL ["C:/PS7/pwsh.EXE", "-command"]
# Install chocolatey
RUN Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# Install application dependencies via chocolatey
RUN choco install -y vcredist140
RUN choco install -y nuget.commandline
# Enable required IIS features
RUN Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebSockets;
RUN Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationInit;
RUN Enable-WindowsOptionalFeature -Online -FeatureName IIS-BasicAuthentication;
RUN Enable-WindowsOptionalFeature -Online -FeatureName IIS-WindowsAuthentication;
RUN Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionDynamic;
# Install IISAdministration to manage IIS configuration
RUN Install-Module -Name IISAdministration -Force -MinimumVersion "1.1.0.0";
# Remove default web site
RUN Remove-IISSite -Name 'Default Web Site'
这会导致调用最后一个命令时出现以下错误
Remove-IISSite: The term 'Remove-IISSite' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
注意:我使用的是 PS7,因为上述容器附带的当前 Powershell 版本不允许我安装 IISAdministration(这有点烦人,但是嘿嘿!可能是我做错了)。
对于当前情况的任何帮助和/或建议将不胜感激!
【问题讨论】:
-
我相信
IISAdministration模块尚未移植到.NET Core。您必须使用当前桌面版本的 PowerShell,即 5.1。 -
@Ash - 感谢您的快速响应。我无法让 PowerShell 5.1 工作,这就是我使用 PS7 的原因。然后我从 ltsc2016 转到 ltsc2019,PowerShell 5.1 运行良好!我猜 2016 版的 Windows Server Core 不附带最新版本的 PowerShell。随意写和回答,我会打勾。
标签: windows powershell docker iis dockerfile