如何在“ SHELL [“ cmd”,“ / S”,“ / C”]“下的Docker RUN命令中使用env变量

时间:2019-05-20 08:59:24

标签: docker docker-compose dockerfile visual-studio-2017-build-tools

如果我在如下所示的文件路径中使用env var“ TEMP_DIR”:

"RUN $env:TEMP_DIR\BuildTools2017\vs_buildtools_2017.exe..."

 "RUN $TEMP_DIR\BuildTools2017\vs_buildtools_2017.exe..."

然后,构建会出错:

  

“系统找不到指定的路径。”

为什么?谢谢,如何避免在文件路径中使用硬编码的"C:\temp"

Dockerfile安装VS 2017的构建工具:

FROM openjdk:8-jdk-windowsservercore

ARG version

ENV TEMP_DIR="c:/temp"

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

# Create temp file for installers
RUN New-Item -ItemType Directory -Force -Path $env:TEMP_DIR;

# Install Visual Studio ultimate 2012
COPY ./VS2012_ultimate "c:/temp/VS2012_ultimate"
RUN \
    Start-Process -FilePath "$env:TEMP_DIR/VS2012_ultimate/vs_ultimate.exe" - ArgumentList '/passive', '/q', '/s', '/norestart', '/noweb', '/full',  -PassThru | Wait-Process;

# Install Blend.Sdk.WPF 4.0 & 4.5
COPY ./BlendSdk "$TEMP_DIR/BlendSdk"

RUN \
    Start-Process -FilePath "$env:TEMP_DIR/BlendSdk/BlendWPFSDK_en.msi" -ArgumentList '/passive', '/norestart' -PassThru | Wait-Process; \
    Start-Process -FilePath "$env:TEMP_DIR/BlendSdk/BlendWPFSDK.msi" -ArgumentList '/passive', '/norestart' -PassThru | Wait-Process;


# Install build tool for VS 2017
SHELL ["cmd", "/S", "/C"]

COPY ./BuildTools2017 "$TEMP_DIR/BuildTools2017"

RUN C:\temp\BuildTools2017\vs_buildtools_2017.exe --quiet --wait --norestart --nocache --noWeb --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools --add Microsoft.VisualStudio.Workload.VCTools
 --add Microsoft.Net.Component.3.5.DeveloperTools --add Microsoft.VisualStudio.Component.Windows10SDK.17763

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

1 个答案:

答案 0 :(得分:0)

Windows公开了%TEMP%环境变量:

RUN %TEMP%\BuildTools2017\vs_buildtools_2017.exe --quiet --wait --norestart --nocache --noWeb --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools --add Microsoft.VisualStudio.Workload.VCTools