简体   繁体   English

Dockerfile 语法 - 如何对 Windows 图像使用 ARG

[英]Dockerfile syntax - How to use ARG for Windows image

I have the following docker file which downloads different things base on an argument passed in from docker-compose (either 2019 or 2022)我有以下 docker 文件,它根据从 docker-compose(2019 年或 2022 年)传入的参数下载不同的内容

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

ARG VSVersion

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

SHELL ["cmd", "/S", "/C"]

RUN if [ "$VSVersion" == "2019" ]; then `
    curl -SL --output vs_buildtools.exe https://aka.ms/vs/16/release/vs_buildtools.exe...

My issue is, the conditional run command is not working - it doesn't install in the above syntax.我的问题是,条件运行命令不起作用 - 它没有安装在上面的语法中。

I also tried using "%VSVersion%"=="2019" because it's default windows shell, but I get error: "2019"=="2019" was unexpected at this time .我也尝试使用“%VSVersion%”=“2019”因为它是默认的 windows shell,但我得到错误: “2019”=“2019”此时是意外的

Could someone please point me towards the right syntax because I've tried various combinations, with and without quotations, to no avail...有人可以指出我正确的语法,因为我尝试了各种组合,有引号和没有引号,都无济于事......

thanks谢谢

Dockerfile is in windows shell not bash, so change the if statement syntax to batch instead of bash: Dockerfile 是 windows shell 而不是 bash,因此将 if 语句语法更改为批处理而不是 bash:

RUN if "%VSVersion%"=="2019"( `
# Download the Build Tools bootstrapper.
curl -SL --output vs_buildtools.exe.. )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM