【问题标题】:Cannot run Remove-IISSite inside a windows docker container无法在 Windows docker 容器中运行 Remove-IISSite
【发布时间】: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


【解决方案1】:

根据您的评论,我在 Server Core 2016 上也遇到了与 PowerShell 模块有关的问题,因此可以表示同情。 IISAdministration 模块尚未移植到 .NET Core。您必须使用当前桌面版本的 PowerShell,即 5.1。

【讨论】:

  • 据我所知,我在这里所说的一切都没有错,所以这是一个讽刺性的投票,没有评论说明原因。
【解决方案2】:

最简单的解决方案是使用Import-Module IISAdministration -UseWindowsPowerShell 而不是Install-Module -Name IISAdministration

这就是 PowerShell 7 以兼容方式加载旧模块的方式(到 5.1 的远程会话),

Reference

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-10
    • 2020-04-12
    • 1970-01-01
    • 2022-07-18
    • 1970-01-01
    • 2019-05-05
    • 2017-03-02
    • 2018-09-21
    相关资源
    最近更新 更多