Can't download Docker and containers on Windows Server 2016 - docker

Im new to docker and windows containers. Deploying on-premise solution on windows server 2016
go through this instruction and stuck on Install-Package Docker -ProviderName DockerMsftProvider -Force
WARNING: Cannot find path
'C:\Users\ADM_AG~1\AppData\Local\Temp\DockerMsftProvider\DockerDefault_DockerSearchIndex.json' because it does not
exist.
WARNING: Cannot bind argument to parameter 'downloadURL' because it is an empty string.
WARNING: The property 'AbsoluteUri' cannot be found on this object. Verify that the property exists.
WARNING: The property 'RequestMessage' cannot be found on this object. Verify that the property exists.
Install-Package : No match was found for the specified search criteria and package name 'Docker'. Try Get-PackageSour
to see all available registered package sources.
At line:1 char:1
Install-Package Docker -ProviderName DockerMsftProvider -Force
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], E
ception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
BUT somehow i've installed Docker
get-service docker
Status Name DisplayName
Stopped docker Docker Engine
start-service docker
start-service : Failed to start service 'Docker Engine (docker)'.
At line:1 char:1
start-service docker
+ CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service], ServiceCommandException
+ FullyQualifiedErrorId : StartServiceFailed,Microsoft.PowerShell.Commands.StartServiceCommand
docker version
Client:
Version: 1.12.0-dev
API version: 1.24
Go version: go1.5.3
Git commit: 8e92415
Built: Thu May 26 17:08:34 2016
OS/Arch: windows/amd64
An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/version: open //./pipe/docker_engine: The system cannot find the file specified.
and now I can't download containers and launch Docker
docker images
An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/images/json: open //./pipe/docker_engine: The system cannot find the file specified.
docker pull mcr.microsoft.com/windows/nanoserver:1809
An error occurred trying to connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/images/create?fromImage=mcr.microsoft.com%2Fwindows%2Fnanoserver&tag=1809: open //./pipe/docker_engine: The system cannot fin
d the file specified.
Containers in WindowsFeauture are enabled, TLS 1.2 is enabled, execution policy is not restricted
may it something related what dockerdefault and container image gallery are not trusted? if yes, how to set it are Trusted?
get-packagesource
Name ProviderName IsTrusted Location
test NuGet False https://www.nuget.org/api/v2
PSGallery PowerShellGet True https://www.powershellgallery.com/api/v2
ContainerImageGallery ContainerImage False http://go.microsoft.com/fwlink/?LinkID=746630&clcid=0x409
DockerDefault DockerMsftPro... False https://go.microsoft.com/fwlink/?LinkID=825636&clcid=0x409

If I were you I would:
Start over by removing docker with:
Option 1 method:
docker ps --quiet | ForEach-Object {docker stop $_}
docker system prune --volumes --all
Uninstall-Package -Name docker -ProviderName DockerMsftProvider
Uninstall-Module -Name DockerMsftProvider
Get-HNSNetwork | Remove-HNSNetwork
Remove-Item "C:\ProgramData\Docker" -Recurse
Option 2, the brute force method:
Stop-Service docker
dockerd --unregister-service
Remove-Item "C:\ProgramData\Docker" -Recurse
Remove-Item "C:\Program Files\Docker" -Recurse
And reboot to a clean system.
Install the Docker Engine from scratch:
# Install Containers feature
Install-WindowsFeature Containers
# RESTART THE SERVER!!!
# Install Docker Module
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
# Install Docker
Install-Package -Name Docker -ProviderName DockerMsftProvider -Force -Confirm:$false
# Start Docker Engine
Start-Service Docker
You should now have a working Docker installation.
Test the docker engine with the commands:
docker version
docker info
If you are still having issues executing the test commands above:
Make sure your Windows Firewall is turned off to make sure there is nothing in the way.
Also, make sure the "World Wide Web Publishing Service" is stopped just in case (at least for now).
Update the "PowerShellGet" module with
Install-Module -Name PowerShellGet -RequiredVersion 2.2.5 -Force
Let me know if it finally works.
FYI:
Container tags with "1809" are for Windows 2019. So:
mcr.microsoft.com/windows/nanoserver:1809 ==> Windows 2019
mcr.microsoft.com/windows/nanoserver:sac2016 ==> Windows 2016
Important: The Windows container must match the Windows host that it will be running on.

Related

How do I remote invoke a windows command from a docker container?

I need to remotely run a command on my window's workstation from my osx workstation using docker.
Works locally:
docker run -it mcr.microsoft.com/powershell pwsh -c "Write-Host 'Hello, World'"`
Hello, World
Doesn't work remote:
docker run -it mcr.microsoft.com/powershell pwsh -c Invoke-Command -ComputerName VM-CHIP -ScriptBlock { Write-Host 'Hello, World' }
Invoke-Command: This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system.
When I try within the container
docker run -it mcr.microsoft.com/powershell
PowerShell 7.2.8
Copyright (c) Microsoft Corporation.
https://aka.ms/powershell
Type 'help' to get help.
PS /> Install-Module -Name PSWSMan
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A
PS /> Install-WSMan
WARNING: WSMan libs have been installed, please restart your PowerShell session to enable it in PowerShell
PS /> Invoke-Command -ComputerName VM-CHIP -ScriptBlock { Write-Host 'Hello, World' }
it fails with
OpenError: [VM-CHIP] Connecting to remote server VM-CHIP failed with the following error message : MI_RESULT_FAILED For more information, see the about_Remote_Troubleshooting Help topic.
I'm confused what the structure is to run this within a single command intead of having to open interactive, and more importantly what am I missing to successfully execute the command on the remote machine instead of this MI_RESULT_FAILED error. Or is this not possible/supported?

Dockerfile (windows): Chocolatey giving "not recognized as the name of a cmdlet" error after nvm install

I'm trying to install NVM in my container by first installing chocolatey. The issue I'm running into is that when building the container after installing nvm through chocolatey when I try to run the "nvm" command to test out if it's been installed I get a nvm : The term 'nvm' is not recognized as the name of a cmdlet error.
My dockerfile is as follows:
# escape=`
#Use the latest Windows Server Core 2019 image.
FROM mcr.microsoft.com/windows/servercore:ltsc2019
# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]
#Adding Chocolatey (a windows package manager)
RUN powershell Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN powershell Get-ChildItem Env:
#Using Chocolatey to install nvm (Node Version Manager)
RUN choco install -y nvm
RUN powershell Import-Module C:\ProgramData\chocolatey\helpers\chocolateyProfile.psm1
RUN powershell refreshenv
RUN powershell nvm
ENTRYPOINT powershell
Here is the output of my docker build -t dockeragent:latest --no-cache . cmd
PS C:\docker\dockeragent> docker build -t dockeragent:latest --no-cache .
Sending build context to Docker daemon 751.1MB
Step 1/9 : FROM mcr.microsoft.com/windows/servercore:ltsc2019
---> e795f3f8aa80
Step 2/9 : SHELL ["cmd", "/S", "/C"]
---> Running in d7dc5ed6ce89
Removing intermediate container d7dc5ed6ce89
---> c7dc93b631eb
Step 3/9 : RUN powershell Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
---> Running in 369cfe083374
Forcing web requests to allow TLS v1.2 (Required for requests to Chocolatey.org)
Getting latest version of the Chocolatey package for download.
Not using proxy.
Getting Chocolatey from https://community.chocolatey.org/api/v2/package/chocolatey/1.2.0.
Downloading https://community.chocolatey.org/api/v2/package/chocolatey/1.2.0 to C:\Users\ContainerAdministrator\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip
Not using proxy.
Extracting C:\Users\ContainerAdministrator\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip to C:\Users\ContainerAdministrator\AppData\Local\Temp\chocolatey\chocoInstall
Installing Chocolatey on the local machine
Creating ChocolateyInstall as an environment variable (targeting 'Machine')
Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'
WARNING: It's very likely you will need to close and reopen your shell
before you can use choco.
Restricting write permissions to Administrators
We are setting up the Chocolatey package repository.
The packages themselves go to 'C:\ProgramData\chocolatey\lib'
(i.e. C:\ProgramData\chocolatey\lib\yourPackageName).
A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'
and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.
Creating Chocolatey folders if they do not already exist.
WARNING: You can safely ignore errors related to missing log files when
upgrading from a version of Chocolatey less than 0.9.9.
'Batch file could not be found' is also safe to ignore.
'The system cannot find the file specified' - also safe.
chocolatey.nupkg file not installed in lib.
Attempting to locate it from bootstrapper.
PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...
WARNING: Not setting tab completion: Profile file does not exist at
'C:\Users\ContainerAdministrator\Documents\WindowsPowerShell\Microsoft.PowerShe
ll_profile.ps1'.
Chocolatey (choco.exe) is now ready.
You can call choco from anywhere, command line or powershell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart powershell and/or consoles
first prior to using choco.
Ensuring Chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder
Removing intermediate container 369cfe083374
---> 6d782b624394
Step 4/9 : RUN powershell Get-ChildItem Env:
---> Running in 66fa6d3c8dc1
Name Value
---- -----
ALLUSERSPROFILE C:\ProgramData
APPDATA C:\Users\ContainerAdministrator\AppData\Roaming
ChocolateyInstall C:\ProgramData\chocolatey
ChocolateyLastPathUpdate 133118979019612509
CommonProgramFiles C:\Program Files\Common Files
CommonProgramFiles(x86) C:\Program Files (x86)\Common Files
CommonProgramW6432 C:\Program Files\Common Files
COMPUTERNAME 66FA6D3C8DC1
ComSpec C:\Windows\system32\cmd.exe
DriverData C:\Windows\System32\Drivers\DriverData
LOCALAPPDATA C:\Users\ContainerAdministrator\AppData\Local
NUMBER_OF_PROCESSORS 4
OS Windows_NT
Path C:\Windows\system32;C:\Windows;C:\Windows\Sys...
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;....
PROCESSOR_ARCHITECTURE AMD64
PROCESSOR_IDENTIFIER Intel64 Family 6 Model 62 Stepping 4, Genuine...
PROCESSOR_LEVEL 6
PROCESSOR_REVISION 3e04
ProgramData C:\ProgramData
ProgramFiles C:\Program Files
ProgramFiles(x86) C:\Program Files (x86)
ProgramW6432 C:\Program Files
PROMPT $P$G
PSModulePath C:\Users\ContainerAdministrator\Documents\Win...
PUBLIC C:\Users\Public
SystemDrive C:
SystemRoot C:\Windows
TEMP C:\Users\ContainerAdministrator\AppData\Local...
TMP C:\Users\ContainerAdministrator\AppData\Local...
USERDOMAIN User Manager
USERNAME ContainerAdministrator
USERPROFILE C:\Users\ContainerAdministrator
windir C:\Windows
Removing intermediate container 66fa6d3c8dc1
---> b4ecb9d7464b
Step 5/9 : RUN choco install -y nvm
---> Running in 19f770d7871d
Chocolatey v1.2.0
Installing the following packages:
nvm
By installing, you accept licenses for the packages.
Progress: Downloading nvm.install 1.1.9... 100%
Progress: Downloading nvm 1.1.9... 100%
nvm.install v1.1.9 [Approved]
nvm.install package files install completed. Performing other installation steps.
Downloading nvm.install
from 'https://github.com/coreybutler/nvm-windows/releases/download/1.1.9/nvm-setup.zip'
Progress: 100% - Completed download of C:\Users\ContainerAdministrator\AppData\Local\Temp\chocolatey\nvm.install\1.1.9\nvm-setup.zip (4.14 MB).
Download of nvm-setup.zip (4.14 MB) completed.
Hashes match.
Extracting C:\Users\ContainerAdministrator\AppData\Local\Temp\chocolatey\nvm.install\1.1.9\nvm-setup.zip to C:\ProgramData\chocolatey\lib\nvm.install\tools...
C:\ProgramData\chocolatey\lib\nvm.install\tools
C:\ProgramData\chocolatey\lib\nvm.install\tools\nvm-setup.exe.ignore
The install of nvm.install was successful.
Software installed to 'C:\ProgramData\chocolatey\lib\nvm.install\tools'
nvm v1.1.9 [Approved]
nvm package files install completed. Performing other installation steps.
The install of nvm was successful.
Software installed to 'C:\ProgramData\chocolatey\lib\nvm'
Chocolatey installed 2/2 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Removing intermediate container 19f770d7871d
---> f8b42ae67241
Step 6/9 : RUN powershell Import-Module C:\ProgramData\chocolatey\helpers\chocolateyProfile.psm1
---> Running in 26740393fea3
Removing intermediate container 26740393fea3
---> 00698d7e89a9
Step 7/9 : RUN powershell refreshenv
---> Running in b2b437ce5170
Refreshing environment variables from registry for cmd.exe. Please wait...Finished..
Removing intermediate container b2b437ce5170
---> 00e6e3e82e62
Step 8/9 : RUN powershell nvm
---> Running in d23b3bd9f50f
nvm : The term 'nvm' 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
+ nvm
+ ~~~
+ CategoryInfo : ObjectNotFound: (nvm:String) [], CommandNotFound
Exception
+ FullyQualifiedErrorId : CommandNotFoundException
The command 'cmd /S /C powershell nvm' returned a non-zero code: 1
My host environment is based on a Manage Mirantis Container Cloud cluster (Mirantis Inc., v1.9.0)
and this is the output of my docker info command
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker Application (Docker Inc., v0.8.0)
cluster: Manage Mirantis Container Cloud clusters (Mirantis Inc., v1.9.0)
registry: Manage Docker registries (Docker Inc., 0.1.0)

Install Docker Windows Server 2019: the term 'docker' is not recognized as the name of a cmdlet, function, script file, or operable program

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.

How to build a Docker-in-Docker image for Docker EE on Windows?

I'm planning to build Docker EE images in dynamic Jenkins agent running in Kubernetes pods and therefore need either
a Docker image providing both the Jenkins Agent functionality and Docker. Currently I'm using jenkins/jnlp-agent:latest-windows as image to run on a Windows LTSC node pool which seems to provide the Jenkins agent functionality adequately or
a way to extend jenkins/jnlp-agent:latest-windows so that it allows to run Docker as well. My naive approach
FROM jenkins/jnlp-agent:latest-windows
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'SilentlyContinue'; $ProgressPreference = 'SilentlyContinue';"]
USER ContainerAdministrator
COPY install-docker.ps1 .
RUN ./install-docker.ps1
RUN Remove-Item install-docker.ps1
with install-docker.ps1 containing
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -ErrorAction Continue
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force -ErrorAction Continue
Install-Package -Force -ErrorAction Continue -Name docker -ProviderName DockerMsftProvider
following https://learn.microsoft.com/en-us/virtualization/windowscontainers/quick-start/set-up-environment?tabs=Windows-Server fails due to
> Start-Service Docker
Start-Service : Failed to start service 'Docker Engine (Docker)'.
At line:1 char:1
+ Start-Service Docker
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service],
ServiceCommandException
+ FullyQualifiedErrorId : StartServiceFailed,Microsoft.PowerShell.Commands.StartServiceCommand
or
a Docker-in-Docker Container for Docker EE on Windows which exposes a Docker TCP socket and allows the Jenkins agent container to connect to it.
The setup should run on Windows Server 2019 node pools provided by Google Kubernetes Engine. I'm aware that Windows Pools are beta currently.
In case someone has an idea how to get the second approach working, it'd still be necessary to run the setup as user jenkins rather than container administrator in order to increase security.
Try to create a service in the Dockerfile.
RUN powershell New-Service -Name “RSDataQualityWorkerPool” -BinaryPathName “C:\WWW\WinServices\RSDataQualityWorkerPool\RSDataQualityWorkerPool.exe”
Start it in the running container.
Start-Service -Name “RSDataQualityWorkerPool”
Take a look here: windows-jnlp-jenkins, docker-service-on-windows.

Running chocolatey in docker container fails

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.

Resources