无法在Docker容器中使用chcolatey安装软件包

时间:2020-02-22 23:41:03

标签: windows powershell docker chocolatey cmdlet

我正在构建一个装有以下软件的Windows容器

  1. 记事本++
  2. MariaDB
  3. HeidiSQL
  4. .NET Framework 2.0和3.5

这是我创建的docker映像。 https://hub.docker.com/repository/docker/mhhaji/winserver2016_base

我尝试过的事情:

运行容器的步骤

docker run --name mycontainer mhhaji/winserver2016_base:v1 ping -t localhost

docker exec -it mycontainer powershell

一旦Powershell运行, 我执行以下命令

Get-PackageProvider
#Chocolatey is not existing so I install chocolatey
Find-Package -Provider chocolatey
#Enter [Y] when prompted
#Install notepad++
Find-Package -Provider chocolatey -name notepad*

我收到以下错误

PS C:\> Find-Package -Provider chocolatey -name notepad* 
WARNING: NuGet: The request was aborted: Could not create SSL/TLS secure channel. 

PS C:\> Find-Package -Provider chocolatey -name mariadb 
Find-Package : No match was found for the specified search criteria and package name 'mariadb' as registered package sources. 
At line:1 char:1 
+ Find-Package -Provider chocolatey -name mariadb 
    + Categorylnfo : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPac
    + FullyQualifiedErrorld : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManage 

PS C:\> Get-PackageSource 
Name          ProviderName    IsTrusted    Location   
chocolatey    Chocolatey      False        http://chocolatey.org/api/v
PSGallery     PowerShellGet   False        https://www.powershellgalle   


PS C:\> Get-PackageParameters
Get-PackageParameters : The term 'Get-PackageParameters' is not recognized as the name 
o program. Check the spelling of the name, or if a path was included, verify that the path 
At line:1 char:1 
+ Get-PackageParameters 
    + Categorylnfo : ObjectNotFound: (Get-PackageParameters:String) [], Command 
    + FullyQualifiedErrorld : CommandNotFoundException 

PS C:\> Get-PackageProvider 
Name           Version         DynamicOptions 
Chocolatey     2.8.5.130       SkipDependencies, ContinueOnFailure, 
ExcludeVersion,ForceX86, PackageSaveMode, FilterOnTag, Contains, 
AllowPrereleaseVersions, Conf  
msi            3.0.0.0         AdditionalArguments  
msu            3.0.0.0 
PowerShellGet  1.0.0.1         PackageManagementProvider, Type, Scope, AllowClobber,SkipPublisherCheck, InstallUpdate, NoPathUpdate, Filter, Tag, Includes, DscRes
Programs       3.0.0.0         IncludeWindowsInstaller, IncludeSystemComponent

我能够下载Chocolatey,因此连接到外部端点似乎不是问题。

更新: 好像我的映像中未安装nuget。寻找解决方案,但找不到。

1 个答案:

答案 0 :(得分:1)

确保您的系统能够支持TLS 1.2,这是运行巧克力的必要条件

PS> [Enum]::GetNames([Net.SecurityProtocolType]) -contains 'Tls12'

为系统启用TLS 1.2

PS> [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12

最后直接从源代码安装巧克力

PS> iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'));