Marcelo Idemax
Marcelo Idemax

Reputation: 2810

Restart Docker container during build process

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

Upvotes: 9

Views: 7414

Answers (3)

MarkusParker
MarkusParker

Reputation: 1596

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/')

Upvotes: 1

ABBAPOH
ABBAPOH

Reputation: 154

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.

Upvotes: 5

Al-waleed Shihadeh
Al-waleed Shihadeh

Reputation: 2855

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

Upvotes: 0

Related Questions