Running chocolatey in docker container fails Running chocolatey in docker container fails docker docker

Running chocolatey in docker container fails


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]::SecurityProtocoltry {  # 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