0

我正在尝试使用 IIS nano docker image 将 webapp 容器化。但是由于 IISAdministration 版本不是最新的(1.0.0.0),因此无法使用“New-IISSiteBinding”命令。新版本是 1.1.0.0

目前,Webapp 运行在 6GB 大小的 iis 核心 docker 映像上,而 iis nano 约为 500MB。因此,如果我可以通过导入 webproxy 模块来完成这项工作,那么我将拥有一个轻量级的图像。

我使用了这个 docker 镜像 microsoft/iis:nanoserver-sac2016

我做了以下步骤

1) Ran Save-Module -Name IISAdministration -Path D:\

此命令在另一台机器上执行,将 D:\IISAdministration 文件夹复制到“C:\Program Files\WindowsPowerShell\Modules\IISAdministration”并重新启动容器。

当我执行 Import-Module -Name IISAdministration 时,我看到了这些错误。如果我删除“C:\Program Files\WindowsPowerShell\Modules\IISAdministration”文件夹并执行“Import-Module -Name IISAdministration”,那么它可以工作。

PS C:\> Import-Module -Name IISAdministration
Import-Module : Could not load file or assembly 'Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
At line:1 char:1
+ Import-Module -Name IISAdministration
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand

PS C:\> Import-Module -Name 'C:\Program Files\WindowsPowerShell\Modules\IISAdministration\1.1.0.0\IISAdministration.psd1'
Import-Module : Could not load file or assembly 'Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
At line:1 char:1
+ Import-Module -Name 'C:\Program Files\WindowsPowerShell\Modules\IISAd ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand

2)我尝试通过命令 Install-Module -Name IISAdministration 安装

我们落后于代理。所以为了下载,我设置了代理变量并尝试下载。然后我得到了这个错误。

PS C:\> .\install_iis.ps1
New-Object : Cannot find type [System.Net.Webproxy]: verify that the assembly containing this type is loaded.
At C:\install_iis.ps1:11 char:44
+ ... equest]::defaultwebproxy = New-Object System.Net.Webproxy($proxy_url)
+                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

The property 'BypassProxyOnLocal' cannot be found on this object. Verify that the property exists and can be set.
At C:\install_iis.ps1:14 char:1
+ [system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

Pre-Install Docker Provider - need Nuget. About to Install..
Install-PackageProvider : Cannot bind parameter 'Proxy'. Cannot convert value "http://:8080" to type "System.Uri".
Error: "Invalid URI: The hostname could not be parsed."
At C:\install_iis.ps1:20 char:87
+ ...  -Verbose -RequiredVersion 2.8.5.201 -Force -Proxy $proxy_url -ProxyC ...
+                                                        ~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Install-PackageProvider], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPac
   kageProvider


NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet
 provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\ContainerAdministrator\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet
provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet
to install and import the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
WARNING: Unable to download the list of available providers. Check your internet connection.
PackageManagement\Install-PackageProvider : No match was found for the specified search criteria for the provider
'NuGet'. The package provider requires 'PackageManagement' and 'Provider' tags. Please check if the specified package
has the tags.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7405 char:21
+ ...     $null = PackageManagement\Install-PackageProvider -Name $script:N ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-Pac
   kageProvider], Exception
    + FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackagePro
   vider

PackageManagement\Import-PackageProvider : No match was found for the specified search criteria and provider name
'NuGet'. Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7411 char:21
+ ...     $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (NuGet:String) [Import-PackageProvider], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProv
   ider

WARNING: Unable to download the list of available providers. Check your internet connection.
PackageManagement\Get-PackageProvider : Unable to find package provider 'NuGet'. It may not be imported yet. Try
'Get-PackageProvider -ListAvailable'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7415 char:30
+ ... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageProvi
   der], Exception
    + FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPacka
   geProvider

Install-Module : NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201'
or newer version of NuGet provider is installed.
At C:\install_iis.ps1:22 char:2
+  Install-Module -Name IISAdministration -RequiredVersion 1.1.0.0
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Install-Module], InvalidOperationException
    + FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Module

我看到 nanoserver 默认不会启用 [System.Net.Webproxy] 模块。
你能帮忙吗

1) 为什么在步骤 1 中手动加载 IISAdministration 包失败。

2) 如果步骤 1 不可行,我如何在导入 [System.Net.Webproxy] 模块及其依赖项后安装 IISAdministration 模块 1.1.0.0。

提前致谢。
毗湿奴

更新 1

我尝试按照@TheIncorrigible1 的建议作为答案。
我将 "iisadministration.1.1.0.nupkg" 复制到 c:\test 并执行 "Register-PSRepository -InstallationPolicy Trusted -Name tmp -SourceLocation C:\test" 。

我看到安装 Nuget 的消息。但它已经在那里了。

在此处输入图像描述

4

1 回答 1

0

简单地将下载文件放到模块文件夹中是无法正确设置的。您可以从 powershellgallery 获取该模块。从这里,它可以部署到您的 nano 服务器上。

接下来,您需要注册一个本地存储库。SourceLocation放置模块 nupkg 的位置。

Register-PSRepository -InstallationPolicy Trusted -Name tmp -SourceLocation C:\tmp

最后:

Install-Module -Name IISAdministration -Repository tmp -Scope AllUsers -Force
于 2018-08-31T03:58:17.410 回答