在构建过程中重启 Docker 容器

Mar*_*lho 5 powershell restart docker dockerfile docker-for-windows

我需要在构建过程中重新启动 Docker 容器dotnetfxDockerfile

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
Run Code Online (Sandbox Code Playgroud)

但我正面临这个错误:

Packages requiring reboot:
 - dotnetfx (exit code 3010) # <--- it means a reboot is needed!
Run Code Online (Sandbox Code Playgroud)

我试图同时运行这两个命令RUNRestart-Computer在它们之间添加(分隔符\)并RUN在每个安装命令之后执行一个命令,但是当我这样做时,它看起来像 Docker 输出丢失了。

我可以在构建过程中重新启动当前容器而不会使 Docker 丢失并保持安装过程吗?


更新 1

dotnetfx在运行最后一个命令之前尝试安装它,但我得到了同样的错误。

# Microsoft .NET Framework (https://chocolatey.org/packages/dotnetfx)
RUN choco install dotnetfx --confirm
Run Code Online (Sandbox Code Playgroud)

错误:

Packages requiring reboot:
 - dotnetfx (exit code 3010)
Run Code Online (Sandbox Code Playgroud)

更新 2(变通方法)

我已经使用已经安装了 .NET 的基本映像设法解决了这个问题:

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8
Run Code Online (Sandbox Code Playgroud)

use*_*518 5

好的,看来您正在尝试安装 VisualStudio 2019。这就是我解决问题的方法。第一种方法是使用如上所述的多阶段构建:

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"
Run Code Online (Sandbox Code Playgroud)

这种方法的问题是 dotnetfx 软件包似乎已损坏 - 由于缺少“alink.dll”库,其他一些软件包无法安装。另外,我没有检查 --ignore-package-exit-codes=3010 是否仅抑制一个错误或所有错误(choco 文档没有提及指定确切代码的可能性)。

第二种方法是从 MS 网站安装 Visual Studio(完美):

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
Run Code Online (Sandbox Code Playgroud)

请注意,您的情况下的组件可能会有所不同。