8

I need to restart the Docker container during the build process due dotnetfx. Dockerfile:

FROM mcr.microsoft.com/windows/servercore:ltsc2019

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Install Chocolatey
RUN 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)
RUN choco install visualstudio2019-workload-universalbuildtools --package-parameters "--includeOptional" --confirm

But I'm facing this error:

Packages requiring reboot:
 - dotnetfx (exit code 3010) # <--- it means a reboot is needed!

I tried to run both commands in the same RUN and adding Restart-Computer between them (separte by \) and executing a RUN command after each installation command either but when I do it looks like Docker output get lost.

Can I restart the current container during the build process without make Docker get lost and keep the installation process?


UPDATE 1

Tried to install this dotnetfx before run the last command but I get the same error.

# Microsoft .NET Framework (https://chocolatey.org/packages/dotnetfx)
RUN choco install dotnetfx --confirm

Error:

Packages requiring reboot:
 - dotnetfx (exit code 3010)

UPDATE 2 (WORKAROUND)

I've manage to workaround this problem using a base image with .NET already installed:

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8
Idemax
  • 2,712
  • 6
  • 33
  • 66
  • I don't know the answer for you question but another option would be to try installing this package on your local machine and copying the executable files into the container with the COPY dockerfile command. Even better, maybe find a docker image with the software already installed. – Bruno Farias Feb 18 '20 at 19:49
  • @BrunoFarias thanks but this is not an option once there are dynamic configuration for this Dockerfile so I would need to figure out this via Dockerfile... – Idemax Feb 18 '20 at 19:51
  • Notice sdk image is 10 GiB large whereas I managed to create an image with only what I need thanks to servercore base image and chocolatey for 5 GiB ! – Yves Martin Feb 23 '21 at 16:28

3 Answers3

5

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 baseimage
RUN 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 dotnetfx
FROM baseimage
RUN 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:1809

RUN powershell -NoProfile -ExecutionPolicy Bypass -Command \
    Invoke-WebRequest "https://aka.ms/vs/16/release/vs_community.exe" \
    -OutFile "%TEMP%\vs_community.exe" -UseBasicParsing

RUN "%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.

ABBAPOH
  • 154
  • 3
  • 11
1

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-amd64

SHELL ["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://learn.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools?vs-2019&view=vs-2019 for a list of available workloads and components
RUN 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/')
MarkusParker
  • 1,264
  • 2
  • 17
  • 35
0

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 baseimage

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Install Chocolatey
RUN 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 baseimage
RUN choco install visualstudio2019-workload-universalbuildtools --package-parameters "--includeOptional" --confirm
Idemax
  • 2,712
  • 6
  • 33
  • 66
Al-waleed Shihadeh
  • 2,697
  • 2
  • 8
  • 22
  • I kinda undestood the multi-stage build but could you give me an example based on my Dockerfile? I'm asking it because is during the last command when this error happen so I'm not sure that this approach would help... – Idemax Feb 18 '20 at 20:11
  • is the above file is the whole file or there are other instructions? – Al-waleed Shihadeh Feb 18 '20 at 20:21
  • I updated the answer, you may need to split this into more than one stage – Al-waleed Shihadeh Feb 18 '20 at 20:34
  • As I said before, the restart problem is throwing while the `RUN choco install visualstudio2019-workload-universalbuildtools --package-parameters "--includeOptional" --confirm` is beign executed not between the command that you splitted... – Idemax Feb 18 '20 at 20:37
  • If you try to run this command alone it will throw you the same error `RUN choco install dotnetfx --confirm` – Idemax Feb 18 '20 at 20:39