Running chocolatey in docker container fails - docker

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.

Related

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)

Docker Desktop for Windows can't run tagged images

I'm trying to do some basic containers in Windows. I've been using Docker on Linux for years, but this issue is new for me.
Running the command
docker build -f windowsTest3.df -t dockertest . results in a good, tagged build.
...
---> 04064df75127
Step 13/13 : ENTRYPOINT C:/BuildTools/Common7/Tools/VsDevCmd.bat
---> Using cache
---> 9e098cff37a2
Successfully built 9e098cff37a2
Successfully tagged dockertest:latest
However, attempting to run an interactive shell inside the container gives an error. The system cannot find the path specified.
Edit: Can't believe I forgot to list the command...
To start the container interactively, I'm running docker run -it dockertest, but I've also tried docker run -it dockertest cmd and variations of that.
Running docker images shows that the tagged image exists, so I can't figure out what's causing the error.
docker images
C:\Users\devuser.DESKTOP-UV8CO47\Desktop\tmp>docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dockertest latest 9e098cff37a2 41 minutes ago 12.3GB
Here are my path locations:
C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\Docker\Docker\Resources\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Python37-32\Scripts\;C:\Program Files (x86)\Python37-32\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\common\bin;C:\Program Files\Amazon\AWSCLI\bin\;C:\Program Files (x86)\GnuWin32\bin;C:\Program Files\CMake\bin;C:\Program Files\dotnet\;C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\ProgramData\chocolatey\bin;C:\PRQA\PRQA-Framework-2.4.0\common\bin;C:\Users\DevUser\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.2\arm\bin;C:\Program Files\Git\bin;C:\Program Files\7-Zip;C:\Program Files\nssm-2.24\win64
Here is a slightly abridged version of the dockerfile
FROM mcr.microsoft.com/windows:10.0.17763.316-amd64
# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]
# Download the Build Tools bootstrapper.
ADD https://aka.ms/vs/16/release/vs_buildtools.exe C:/tmp/vs_buildtools.exe
# Install Build Tools excluding workloads and components with known issues.
RUN C:/tmp/vs_buildtools.exe --quiet --wait --norestart --nocache \
--installPath C:\BuildTools \
--all \
--remove Microsoft.VisualStudio.Component.Windows10SDK.10240 \
--remove Microsoft.VisualStudio.Component.Windows10SDK.10586 \
--remove Microsoft.VisualStudio.Component.Windows10SDK.14393 \
--remove Microsoft.VisualStudio.Component.Windows81SDK \
|| IF "%ERRORLEVEL%"=="3010" EXIT 0
ENV chocolateyUseWindowsCompression=false
RUN powershell set-executionpolicy remotesigned
RUN powershell -Command Invoke-Expression ((New-Object Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
RUN powershell -Command Install-PackageProvider -Name chocolatey -Force
RUN powershell -command "choco install -y git"
ENTRYPOINT C:/BuildTools/Common7/Tools/VsDevCmd.bat
Please check if VsDevCmd.bat is available inside the container when it's starting, at C:/BuildTools/Common7/Tools/ path
Also as per this Doc reference
On Windows, file paths specified in the CMD instruction must use
forward slashes or have escaped backslashes \.
CMD c:\Apache24\bin\httpd.exe -w
Maybe try your ENTRYPOINT like this.
ENTRYPOINT C:\\BuildTools\\Common7\\Tools\\VsDevCmd.bat
You can also use CMD
CMD C:\\BuildTools\\Common7\\Tools\\VsDevCmd.bat
Can also try this as well but recommended is above one
ENTRYPOINT C:\BuildTools\Common7\Tools\VsDevCmd.bat

Opening folder with Remote-Container fails due to PowerShell being used to execute Dockerfile build steps

I was hoping to test out the new Remote Development extension using the Remote-Containers functionality. I grabbed the sample Python project and opened it using the Remote-Containers: Open Folder in Container... function.
The initialisation process kicks off fine, stepping through some of the Docker build without problem. Steps 1-3 in the Dockerfile succeed and then step 4 (lines 13/14 of the Dockerfile) throws an exception and exits because the RUN command includes an AND_IF operator (&&). This is because it's being passed as a subcommand to PowerShell which doesn't support &&.
I've followed the instructions for preparing my system for using the Remote-Containers functionality, including adding both my drives (C: and D:) to the Shared Drives.
Troubleshooting I've tried so far:
switching between Linux and Windows containers
swapping between PowerShell, Git Bash, and WSL (Ubuntu) as the default shell for Visual Code (terminal.integrated.shell.windows)
using one of the other Remote-Container examples from Microsoft
creating a very basic project with one simple Python file and attempting the Remote-Containers: Open Folder in Container... again, selecting python:3 as the targeted Docker image
None of the above steps have produced any different outcomes.
Docker Inspect reveals that the Config->Shell setting is:
"Shell":
[
"powershell",
"-Command",
"$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"
]
while the Config->Cmd setting is:
"Cmd":
[
"powershell",
"-Command",
"$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';",
"apt-get update && apt-get -y install --no-install-recommends apt-utils 2>&1"
]
The full container config is here.
The reason for the exception is obvious but I can't discern why the Dockerfile RUN instruction is being passed to PowerShell like above.
I'm running Visual Studio Code - Insiders (1.36.0-insider) and Docker Engine 18.09.2 on Windows 10 (1809).
The exception produces the following error when step 4 fails (I've included the preceding successful steps for context; flattened the pip install in step 2 for brevity):
Setting up container for folder: d:\Development\vscode-remote-try-python-master
Run: docker build -f d:\Development\vscode-remote-try-python-master\.devcontainer\Dockerfile -t vsc-vscode-remote-try-python-master-486294f4d73f25a657ec08f53ff07d5f d:\Development\vscode-remote-try-python-master
Sending build context to Docker daemon 24.06kB
Step 1/13 : FROM python:3
---> 22a423a5db36
Step 2/13 : RUN pip install pylint
---> Running in 23380af29dd1
Successfully installed astroid-2.2.5 colorama-0.4.1 isort-4.3.20 lazy-object-proxy-1.4.1 mccabe-0.6.1 pylint-2.3.1 six-1.12.0 typed-ast-1.4.0 wrapt-1.11.1
Removing intermediate container 23380af29dd1
---> 5569fa48c9c5
Step 3/13 : ENV DEBIAN_FRONTEND=noninteractive
---> Running in 941086f674cb
Removing intermediate container 941086f674cb
---> b8b2fd47bdb1
Step 4/13 : RUN apt-get update && apt-get -y install --no-install-recommends apt-utils 2>&1
---> Running in defcc073adcf
At line:1 char:91
+ ... ; $ProgressPreference = 'SilentlyContinue'; apt-get update && apt-get ...
+ ~~
The token '&&' is not a valid statement separator in this version.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : InvalidEndOfLine
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; apt-get update && apt-get -y install --no-install-recommends apt-utils 2>&1' returned a non-zero code: 1
Failed: Building an image from the Dockerfile.
Command failed: C:\Program Files\Docker\Docker\Resources\bin\docker.exe build -f d:\Development\vscode-remote-try-python-master\.devcontainer\Dockerfile -t vsc-vscode-remote-try-python-master-486294f4d73f25a657ec08f53ff07d5f d:\Development\vscode-remote-try-python-master
Is this a common experience for anyone else? Would appreciate any solutions or suggestions for troubleshooting further.
This issue seemingly results from the use of Windows Containers, as discussed in this GitHub issue.
Yeah, unfortunately Windows Containers are not supported and using LCOW in "Windows Containers mode" for Docker Desktop is not something we really support right now given its experimental state.
LCOW still has gaps like supporting single file bind mounting that can cause issues and things like PostgreSQL are called out as not working yet. See here and here.
The Windows recommendation right now is primarily to use LCOW on an exception basis:
When to use Moby VM
Right now, we recommend the Moby VM method of running Linux containers to people who:
Want a stable container environment. This is the Docker for Windows default.
Run Windows or Linux containers, but rarely both at the same time.
Have complicated or custom networking requirements between Linux containers.
Don't need kernel isolation (Hyper-V isolation) between Linux containers.
When to use LCOW
Right now, we recommend LCOW to people who:
Want to test our newest technology.
Run Windows and Linux containers at the same time.
Need kernel isolation (Hyper-V isolation) between Linux containers.

Error building a docker in Windows 10

I'm trying to build a docker image from a really simple project, just to start understanding how docker works and communicate. So, I have created a WebApi project, with just one method that returns a 200.
Once the project has been created, I created the dockerfile:
# TP5 for technology preview (will not be needed when we go GA)
# FROM microsoft/iis
FROM microsoft/iis:TP5
MAINTAINER Roman_Hervas
# Install Chocolatey (tools to automate commandline compiling)
ENV chocolateyUseWindowsCompression='false'
RUN #powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
# Install build tools
RUN powershell add-windowsfeature web-asp-net45 \
&& choco install microsoft-build-tools -y --allow-empty-checksums -version 14.0.23107.10 \
&& choco install dotnet4.6-targetpack --allow-empty-checksums -y \
&& choco install nuget.commandline --allow-empty-checksums -y \
&& nuget install MSBuild.Microsoft.VisualStudio.Web.targets -Version 14.0.0.3 \
&& nuget install WebConfigTransformRunner -Version 1.0.0.1
RUN powershell remove-item C:\inetpub\wwwroot\iisstart.*
# Copy files (temporary work folder)
RUN md c:\build
WORKDIR c:/build
COPY . c:/build
# Restore packages, build, copy
RUN nuget restore \
&& "c:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /p:Platform="Any CPU" /p:VisualStudioVersion=12.0 /p:VSToolsPath=c:\MSBuild.Microsoft.VisualStudio.Web.targets.14.0.0.3\tools\VSToolsPath WebApiDocker.sln \
&& xcopy c:\build\WebApiDocker\* c:\inetpub\wwwroot /s
# NOT NEEDED ANYMORE –> ENTRYPOINT powershell .\InitializeContainer
And the InitializeContainer:
If (Test-Path Env:\ASPNET_ENVIRONMENT)
{
\WebConfigTransformRunner.1.0.0.1\Tools\WebConfigTransformRunner.exe \inetpub\wwwroot\Web.config "\inetpub\wwwroot\Web.$env:ASPNET_ENVIRONMENT.config" \inetpub\wwwroot\Web.config
}
# prevent container from exiting
powershell
So, finally, I try to execute the command to build the project: docker build -t dockerexample .
The result is a failure with the following message (step 4):
Step 1/10 : FROM microsoft/iis:TP5
---> accd044753c1
Step 2/10 : MAINTAINER Roman_Hervas
---> Using cache
---> e42af9c57e0d
Step 3/10 : ENV chocolateyUseWindowsCompression 'false'
---> Using cache
---> 24621a9f18d9
Step 4/10 : RUN #powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iex ((New-Object System.Net.WebClient).D
ownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
---> Running in 61199189917a
container 61199189917a0057fb54dddca6d80a6c6f9e8b77d2326379537684f58fefbe50 encountered an error during CreateContainer:
failure in a Windows system call: A connection could not be established with the Virtual Machine hosting the Container.
(0xc0370108) extra info: {"SystemType":"Container","Name":"61199189917a0057fb54dddca6d80a6c6f9e8b77d2326379537684f58fefb
e50","Owner":"docker","IsDummy":false,"IgnoreFlushesDuringBoot":true,"LayerFolderPath":"C:\\ProgramData\\Docker\\windows
filter\\61199189917a0057fb54dddca6d80a6c6f9e8b77d2326379537684f58fefbe50","Layers":[{"ID":"08b847bd-7f7e-5758-90be-43262
e170e22","Path":"C:\\ProgramData\\Docker\\windowsfilter\\64e43de6efd9eee001b12f6ed8add83d1aefff6cb5f8b55e9a44c4b1b2f27b8
0"},{"ID":"293472e6-599f-5a8e-b531-ac7499b0c900","Path":"C:\\ProgramData\\Docker\\windowsfilter\\cfb71fcbe2f95caa2a5306d
800c3d649067c00702a26a208ead6f5fed58e49c8"},{"ID":"baacc247-5374-5761-812f-e1ad911fda31","Path":"C:\\ProgramData\\Docker
\\windowsfilter\\89144a071d22e130e0ca9a069857a181b8976e9557c95395fb58116358dd5a02"},{"ID":"3d538ae4-eaf0-574c-b274-30bba
ce1a9b0","Path":"C:\\ProgramData\\Docker\\windowsfilter\\e2ff3bea019eaee94ab33312b6a39d6305b85df9b0b950680aa38e55eec5437
1"},{"ID":"937e8340-c320-5f09-a87e-9cd5912f40bb","Path":"C:\\ProgramData\\Docker\\windowsfilter\\0dd23a484fe7eea9da274be
8e6e1f0768b52a8a121e7bf274d5974ada02400d8"}],"HostName":"2ac70997c0f2","MappedDirectories":[],"SandboxPath":"C:\\Program
Data\\Docker\\windowsfilter","HvPartition":true,"EndpointList":["deb85df1-5dba-4394-a1ac-77f4a106e31a"],"HvRuntime":{"Im
agePath":"C:\\ProgramData\\Docker\\windowsfilter\\0dd23a484fe7eea9da274be8e6e1f0768b52a8a121e7bf274d5974ada02400d8\\Util
ityVM"},"Servicing":false,"AllowUnqualifiedDNSQuery":true}
I'm totally noob with Docker, so I have no idea of the problem here, and Google has not been too much helpful. My operating system is Windows 10 Pro, and Docker version is 17.03.1-ce-win12 (12058).
Question:
Why is it launching an error in step 4?
Thank you very much in advance.

Adding SSL certificates to Website to Docker

I have a website that runs on ssl i.e. https, I want to deploy it to Docker Windows Containers with Docker Desktop for Windows. So I wanted to ask how can it be done, I have added the certificates to the container, and when I use
RUN powershell -NoProfile -Command certmgr.exe -add MyCert.cer -s -r localMachine trustedpublisher
It gives this error.
certmgr.exe : The term 'certmgr.exe' 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.
So can you explain how would it be done?
certmgr.exe
needs Visual Studio so it cant be run in Containers. Following is a way to do it if it helps anyone. Add this in the docker file when you are creating the image
RUN mkdir C:\cert
#cert folder contains the certificates YourCertificate.cer & Name.pfx
ADD cert/ /cert
RUN powershell -NoProfile -Command \
certutil -addstore "Root" "C:/cert/YourCertificate.cer"
RUN powershell -NoProfile -Command \
certutil -importpfx -p "password" "C:/cert/Name.pfx"
RUN powershell -NoProfile -Command \
New-WebBinding -Name "YourWebsite" -IP "*" -Port 1234 -Protocol https
RUN powershell -NoProfile -Command \
get-item cert:\LocalMachine\MY\thumbprint-of-your-cert | New-Item 0.0.0.0!1234
1234 is the port which you can bind with your website. It will bind your website to the certificate.

Resources