繁体   English   中英

无法在 windows docker 容器内运行 Remove-IISSite

[英]Cannot run Remove-IISSite inside a windows docker container

哟,stackoverflow-ers!

我最近在尝试创建运行 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(这有点烦人,但是嘿嘿。可能是我做错了)。

任何有关当前情况的帮助和/或建议将不胜感激!

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

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

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

参考

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM