I have been trying to install Chocolatey on a windows container and I get the below DownloadString exception.
Tried with RUN powershell -Command [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 to add Tls12 explicitly. Tried FROM mcr.microsoft.com/windows:20H2 and FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8 base images and I get the same error.
Dockerfile
ROM mcr.microsoft.com/windows/servercore:ltsc2019
USER ContainerAdministrator
RUN powershell -Command [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
RUN powershell -Command Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Exception I am getting -
Exception calling "DownloadString" with "1" argument(s): "The underlying
connection was closed: An unexpected error occurred on a send."
At line:1 char:166
+ ... -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('ht ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
Host OS - Windows 10 Enterprise x64 v10.0.19044 Build 19044
Hyper-V Manager - v10.0.19041.1
Related
I'm installing dbatools to run on a Ubuntu Container.
Error:
Could not import /usr/local/share/powershell/Modules/dbatools/1.1.142/bin/smo/coreclr/System.Security.SecureString.dll : Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'System.Security.SecureString, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'."
At /usr/local/share/powershell/Modules/dbatools/1.1.142/internal/scripts/libraryimport.ps1:150 char:21
+ [Reflection.Assembly]::LoadFrom($assemblyPath)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FileLoadException
Import-Module : The specified module '/usr/local/share/powershell/Modules/dbatools/1.1.142/bin/dbatools.dll' was not loaded because no valid module file was found in any module directory.
At /Test5.ps1:12 char:1
+ Import-Module dbatools
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (/usr/local/share/po\u202642/bin/dbatools.dll:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
My Dockerfile
From myImage
RUN pwsh -Command 'Set-PSRepository -Name PSGallery -InstallationPolicy Trusted'
RUN pwsh -command "Install-Module sqlserver -Scope AllUsers -Force"
RUN pwsh -command "Install-Module dbatools -Scope AllUsers -Force"
RUN pwsh -command "Get-module -ListAvailable -Name 'dbatools'"
RUN pwsh -command "Get-module -ListAvailable -Name 'sqlserver'"
COPY Test5.ps1 .
CMD [ "pwsh", "Test5.ps1"]
myImage contains the requred setup to run powershell on ubuntu 20.
Test5.ps1
Import-Module dbatools
What do I need to do to make my powershell module work without needing to be manually imported?
THANKS!
dbatools raise this as an issue and to be fix on 2.0.
Trying to install Docker in process isolation on Windows Server 2019 and following these steps. (I can't use Hyper-V on this server) when running PowerShell in admin mode.
I however get the error
Get-PackageProvider : A parameter cannot be found that matches parameter name 'ListAvailableget-packagesource'
I also tried Install-Package -Name docker -ProviderName DockerMsftProvider
I then get:
Install-Package : Unable to find package providers (DockerMsftProvider).
At line:1 char:1
+ Install-Package -Name docker -ProviderName DockerMsftProvider
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], E
xception
+ FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
Install-Package : Unable to find package providers (DockerMsftProvider).
At line:3 char:1
+ Install-Package -Name docker -ProviderName DockerMsftProvider
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], E
xception
+ FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
UPDATE 1
I had to set the PowerShell execution policy to unrestricted like so (I'll set it back to Restricted Set-ExecutionPolicy -ExecutionPolicy Restricted after all this):
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
I also had to temporarily disable some antivirus/malware protection from Windows Defender. For me antimalware was already disabled so I had to also disable real-time virus protection.
I then could run
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Now via Get-PackageProvider -ListAvailable I see that DockerMsftProvider is installed.
Name Version DynamicOptions
---- ------- --------------
DockerMsftProvider 1.0.0.8 Update
msi 3.0.0.0 AdditionalArguments
msu 3.0.0.0
NuGet 2.8.5.208 Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag...
PowerShellGet 1.0.0.1 PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, ...
Programs 3.0.0.0 IncludeWindowsInstaller, IncludeSystemComponent
I ran Install-Package -Name docker -ProviderName DockerMsftProvider and entered Y.
I then run Get-Package -Name Docker -ProviderName DockerMsftProvider and get:
Name Version Source ProviderName
---- ------- ------ ------------
docker 20.10.0 DockerDefault DockerMsftProvider
When I run Install-Package -Name docker -ProviderName DockerMsftProvider I get no feedback via PowerShell, no errors, so I think it's good.
However, when I checked here and ran docker run --isolation=process mcr.microsoft.com/windows/nanoserver:1809 cmd.exe /c ping 127.0.0.1 -t
I get the error
docker : The term 'docker' 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.
At line:1 char:1
+ docker run --isolation=process mcr.microsoft.com/windows/nanoserver:1 ...
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (docker:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
In the past I had tried to install Docker Desktop, which I then uninstalled since my VPS does not support Hyper-V.
I'm not sure if this is still from that install or new, but I added path C:\Program Files\Docker to my environment PATH variable.
Still I get the same error
The term 'docker' is not recognized as the name of a cmdlet, function, script file, or operable program.
UPDATE 2
Based on #Peter Wishart's answer I checked my PATH system variables, but Docker can be seen there (see screenshot below) and as Peter also mentioned, since I can run docker --version via the command prompt (not PowerShell) the install did complete successfully.
UPDATE 3
I checked ($env:path).Split(";") in PowerShell and the Docker path is there:
How can I install Docker?
I use a script that installs the containers feature and uninstalls Windows Defender (n.b. this may or may not be safe for your environment):
$rebootNeeded = $false
if (-not (Get-WindowsFeature Containers).Installed) {
$rebootNeeded = $rebootNeeded -or (Install-WindowsFeature -Name Containers).RestartNeeded
}
if ((Get-WindowsFeature Windows-Defender).Installed) {
$rebootNeeded = $rebootNeeded -or (Uninstall-WindowsFeature Windows-Defender).RestartNeeded
}
if ($rebootNeeded) { throw "Reboot then rerun to complete docker installation" }
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Install-Package -Name docker -ProviderName DockerMsftProvider -Force
Start-Service docker
docker --version
I mention this in case its an option to just reset the machine if nothing else works...
I think your first problem was a copy/paste error at the Get-PackageProvider step.
The files you listed are the correct ones for the latest DockerEE version.
If you run docker directly from there e.g. &"C:\Program Files\Docker\docker.exe" --version and it doesn't work, then there's an environmental problem other than the path - try reinstalling Docker.
If you restart Powershell and run ($env:path).Split(";"), the only Docker entry should be C:\Program Files\Docker - perhaps there are some leftovers from Docker Desktop interfering?
[Edit]
It appears that the system path was corrupted in a subtle way (although the docker path was present and correct).
I think if you check the path configuration carefully and/or move the docker path nearer the start of the path, you should be able to get a permanent fix.
Inside Dockerfile
# escape=`
FROM microsoft/iis
SHELL ["powershell", "-command"]
RUN Install-WindowsFeature Web-ASP
WORKDIR /inetpub/wwwroot
COPY . .
Once I build I get the below error
Step 3/5 : RUN Install-WindowsFeature Web-ASP ---> Running in
f1b57ea65228 Install-WindowsFeature : The request to add or remove
features on the specified server failed. Installation of one or more
roles, role services, or features failed. Error: 0x800f0922 At line:1
char:1
+ Install-WindowsFeature Web-ASP
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (#{Vhd=; Credent...Name=localh ost}:PSObject) [Install-WindowsFeature],
Exception
+ FullyQualifiedErrorId : DISMAPI_Error__Failed_To_Enable_Updates,Microsof
t.Windows.ServerManager.Commands.AddWindowsFeatureCommand
Success Restart Needed Exit Code Feature Result
------- -------------- --------- -------------- False No Failed {}
The command 'powershell -command Install-WindowsFeature Web-ASP'
returned a non-zero code: 1
I have to say that I'm new to Docker and Dockerfiles... I need to create a build that has a nano server and java installed.
I've created the following docker file, but I got the error below
Here's the file
# Installer image
FROM mcr.microsoft.com/windows/servercore:1909 AS installer
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Invoke-WebRequest -OutFile java.zip https://download.oracle.com/otn-pub/java/jdk/13.0.2+8/d4173c853231432d94f001e99d882ca7/jdk-13.0.2_windows-x64_bin.zip;`
Expand-Archive java.zip -DestinationPath java; `
And the error is
Error response from daemon: Dockerfile parse error line 8: unknown instruction: EXPAND-ARCHIVE
What am I doing wrong? I'm on a Windows Container runtime
Thanks
Microsoft's documentation now mention to use the \ to escape over multiple lines
RUN Write-Host "pwsh .bak copied across"; \
Get-ChildItem -Path /var/opt/mssql/backup \
Invoke-Sqlcmd -query "SELECT GETDATE() AS TimeOfQuery" \
Invoke-Sqlcmd -query "SELECT * from sys.databases" \
https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/manage-windows-dockerfile#escape-character
Changed it to the following and tested. the error is gone.
# Installer image
FROM mcr.microsoft.com/windows/servercore:10.0.14300.1030 AS installer
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';
$ProgressPreference = 'SilentlyContinue';"]
RUN Invoke-WebRequest -OutFile java.zip https://download.oracle.com/otn-pub/java/jdk/13.0.2+8/d4173c853231432d94f001e99d882ca7/jdk-13.0.2_windows-x64_bin.zip;
CMD [ "Expand-Archive", "java.zip", "-DestinationPath java;" ]
I have docker on windows server 2016. The Dockerfile contains some build tools to be installed via chocolatey. It fails every time when I am trying to build image from mentioned Dockerfile. The chocolatey tool is not running in container.
# Use the latest Windows Server Core image.
FROM microsoft/windowsservercore
ENV chocolateyUseWindowsCompression false
RUN powershell -Command \
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')); \
choco feature disable --name showDownloadProgress
RUN choco install visualstudio2015professional
RUN choco install qtcreator
RUN choco install curl
RUN choco install jq
RUN choco install 7zip.install
RUN choco install jfrog-cli
RUN choco install jom
Build command here.........
C:\Program Files\Docker>docker build -t test -f Dockerfile.txt .
Sending build context to Docker daemon 54.73MB
Step 1/10 : FROM microsoft/windowsservercore
latest: Pulling from microsoft/windowsservercore
3889bb8d808b: Pull complete
fb1ebf2c42b6: Pull complete
Digest: sha256:750440935dd3ef8ea148a8e4f83a0397540a8014938ae7b59eb78211da1d5969
Status: Downloaded newer image for microsoft/windowsservercore:latest
---> 7d89a4baf66c
Step 2/10 : ENV chocolateyUseWindowsCompression false
---> Running in 8a7b1fc97da5
---> 0f3c89daf01c
Removing intermediate container 8a7b1fc97da5
Step 3/10 : RUN powershell -Command iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')); choco feature disable --name showDownloadProgress
---> Running in f7088454db37
Exception calling "DownloadString" with "1" argument(s): "Unable to connect to
the remote server"
At line:1 char:1
+ iex ((new-object net.webclient).DownloadString('https://chocolatey.or ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
choco : The term 'choco' 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.
At line:1 char:88
+ ... .DownloadString('https://chocolatey.org/install.ps1')); choco feature ...
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (choco:String) [], CommandNotFou
ndException
+ FullyQualifiedErrorId : CommandNotFoundException
The command 'cmd /S /C powershell -Command iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')); choco feature disable --name showDownloadProgress' returned a non-zero code: 1
I had this problem a while ago. It was destroying me for some time, I could not work out why one Docker image I had was building fine while the next one was not.
I finally traced it to an issue with restricted TLS, whereby the newer Windows docker base images required TLS1.2 which is not enabled by default. You may be encountering this with your windows server core base container.
The Chocolatey documentation refers to this situation in their section about installing-with-restricted-tls.
Their fix at time of writing was to do a little musical chairs with the TLS settings before putting them back - see below
$securityProtocolSettingsOriginal = [System.Net.ServicePointManager]::SecurityProtocol
try {
# Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48)
# Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't
# exist in .NET 4.0, even though they are addressable if .NET 4.5+ is
# installed (.NET 4.5 is an in-place upgrade).
[System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48
} catch {
Write-Warning 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to do one or more of the following: (1) upgrade to .NET Framework 4.5 and PowerShell v3, (2) specify internal Chocolatey package location (set $env:chocolateyDownloadUrl prior to install or host the package internally), (3) use the Download + PowerShell method of install. See https://chocolatey.org/install for all install options.'
}
iex ((New-Object
System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
[System.Net.ServicePointManager]::SecurityProtocol = $securityProtocolSettingsOriginal
Failing that, run your container without choco using docker run --name mycontainer -d [your container id] then use an interactive shell using docker exec -it mycontainer powershell and you'll be able to run the choco install interactively to get more information about the failure.
For me this turned out to be my antivirus specifically Symantec in my case, worked as soon as it was disabled.
Did you research following from https://github.com/chocolatey/choco/issues/1055
SET chocolateyUseWindowsCompression='false' REM No spaces in the equals
#powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
And closest question here: Powershell unable to connect to internet at all
I managed to install choco from web in a corp network with proxy settings.
first step is creating a proxy.ps1:
$ProxyAddress = "http://proxy:port"
[system.net.webrequest]::defaultwebproxy = New-Object system.net.webproxy($ProxyAddress)
$CredCache = [System.Net.CredentialCache]::new()
$NetCreds = [System.Net.NetworkCredential]::new("username","password","")
$CredCache.Add($ProxyAddress, "Basic", $NetCreds)
[system.net.webrequest]::defaultwebproxy.credentials = $CredCache
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true
and then in Dockfile, do it this way:
FROM mcr.microsoft.com/windows:1809-amd64 AS base
SHELL ["cmd", "/S", "/C"]
# add proxy to powershell profile for all users
ADD proxy.ps1 C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
# Install Chocolatey
RUN powershell -ExecutionPolicy unrestricted -Command `
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
The key is in the error message:
"Unable to connect to the remote server"
Your Docker container doesn't have internet connectivity to download the Chocolatey install script.