Restart Docker container during build process Restart Docker container during build process powershell powershell

Restart Docker container during build process


OK, looks like you're trying to install VisualStudio 2019. That's how I solved the problem.The first approach is to use multi-stage build as stated above:

FROM mcr.microsoft.com/windows/servercore:1809 as baseimageRUN powershell -NoProfile -ExecutionPolicy Bypass -Command \         $Env:chocolateyVersion = '0.10.15' ; \     $Env:chocolateyUseWindowsCompression = 'false' ; \     "[Net.ServicePointManager]::SecurityProtocol = \"tls12, tls11, tls\"; iex ((New-Object System.Net.WebClient).DownloadString('http://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"# suppress the "restart required" error code (3010)RUN choco install -y --ignore-package-exit-codes=3010 dotnetfx# emulate the required restart after installing dotnetfxFROM baseimageRUN choco install -y visualstudio2019buildtools --package-parameters \    "--norestart --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"

The problem with that approach is that dotnetfx package seems to be broken - some other packages fail to install due to the missing 'alink.dll' library. Also, I didn't check that --ignore-package-exit-codes=3010 suppresses only one error or all errors (choco doc says nothing about the possibility to specify the exact code).

The second approach is to install visual studio from the MS website (works perfectly):

FROM mcr.microsoft.com/windows/servercore:1809RUN powershell -NoProfile -ExecutionPolicy Bypass -Command \    Invoke-WebRequest "https://aka.ms/vs/16/release/vs_community.exe" \    -OutFile "%TEMP%\vs_community.exe" -UseBasicParsingRUN "%TEMP%\vs_community.exe"  --quiet --wait --norestart --noUpdateInstaller \    --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 \    --add Microsoft.VisualStudio.Component.Windows10SDK.18362

Note that components might be different in you case.


one way to solve this issue is to use multi-stage build. In the first stage, you can install the binary and in the second one, you copy the binary and build the docker image.

Here is how you can do this: https://docs.docker.com/develop/develop-images/multistage-build/

example

FROM mcr.microsoft.com/windows/servercore:ltsc2019 as baseimageSHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]# Install ChocolateyRUN Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))# Universal Windows Platform build tools workload for Visual Studio 2019 Build Tools (https://chocolatey.org/packages/visualstudio2019-workload-universalbuildtools#dependencies)FROM baseimageRUN choco install visualstudio2019-workload-universalbuildtools --package-parameters "--includeOptional" --confirm


The restart is not necessary in docker. The only things one has to do is to tell choco not to exit with a non-zero exit code. This is done by --ignore-package-exit-codes=3010.

The following worked for me:

FROM mcr.microsoft.com/windows/servercore:1809-amd64SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]RUN ["powershell","Set-ExecutionPolicy Bypass -Scope Process -Force;","iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"]RUN choco install dotnetfx -y --version 4.8.0.20190930 --ignore-package-exit-codes=3010# see https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools?vs-2019&view=vs-2019 for a list of available workloads and componentsRUN choco install visualstudio2019buildtools -y --version 16.8.1.0 --params \"--add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools --add Microsoft.VisualStudio.Workload.NetCoreBuildTools\" RUN setx /M PATH $($Env:PATH+';C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/MSBuild/Current/bin/;c:/Program Files (x86)/Microsoft SDKs/Windows/v10.0A/bin/NETFX 4.8.0 Tools/')