考慮以下Dockerfile. RUN它嘗試通過在單個命令中下載、安裝然后洗掉安裝程式來安裝 Visual Studio 構建工具。
FROM mcr.microsoft.com/windows/servercore:ltsc2022
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
RUN Invoke-WebRequest \
-Uri https://aka.ms/vs/17/release/vs_buildtools.exe \
-OutFile vs_buildtools.exe; \
.\vs_buildtools.exe --nocache --norestart --quiet --wait \
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 \
--add Microsoft.VisualStudio.Component.Windows10SDK.19041; \
Remove-Item -Path vs_buildtools.exe
構建映像時,安裝程??序已下載并啟動,然后在安裝完成之前嘗試洗掉安裝程式!這當然會產生錯誤:
Remove-Item : Cannot remove item C:\vs_buildtools.exe: The process cannot
access the file 'C:\vs_buildtools.exe' because it is being used by another
process.
錯誤后繼續構建,完成安裝。
為什么在完成Remove-Item之前執行.\vs_buildtools.exe?
如果我Remove-Item拿出自己的RUN命令,它作業正常:
RUN Invoke-WebRequest \
-Uri https://aka.ms/vs/17/release/vs_buildtools.exe \
-OutFile vs_buildtools.exe; \
.\vs_buildtools.exe --nocache --norestart --quiet --wait \
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 \
--add Microsoft.VisualStudio.Component.Windows10SDK.19041
RUN Remove-Item -Path vs_buildtools.exe
uj5u.com熱心網友回復:
一種解決方法是使用cmd而不是powershell.
以下兩種方法都有效:
RUN Invoke-WebRequest \
-Uri https://aka.ms/vs/17/release/vs_buildtools.exe \
-OutFile vs_buildtools.exe; \
cmd /c "vs_buildtools.exe --nocache --norestart --quiet --wait \
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 \
--add Microsoft.VisualStudio.Component.Windows10SDK.19041"; \
Remove-Item -Path vs_buildtools.exe
SHELL ["cmd", "/S", "/C"]
RUN curl -SL https://aka.ms/vs/17/release/vs_buildtools.exe -o vs_buildtools.exe \
&& call vs_buildtools.exe --nocache --norestart --quiet --wait \
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 \
--add Microsoft.VisualStudio.Component.Windows10SDK.19041 \
&& call del /q vs_buildtools.exe
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/475911.html
標籤:码头工人 电源外壳 dockerfile
