How to use the ARG instruction of Dockerfile for Windows image

我的未来我决定 提交于 2019-12-06 11:09:58

(This answer is the formalized version of my comment.)

Try to use %FirefoxVersion%

ARG FirefoxVersion
RUN powershell -Command iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'));
RUN choco install -y firefox --version %FirefoxVersion% --ignore-checksums

Reason:

The error message "The command 'cmd /S /C choco install ...' returned a non-zero code: 1" indicates that the choco install command is executed on cmd.exe (Windows' Command Prompt). Dockerfile's ARG value can be treated as an environment variable. On cmd.exe, %...% stands for env var.

As @matt9 suggested

Use $env:FirefoxVersion in powershell

Use %FirefoxVersion% in cmd.exe

FROM microsoft/windowsservercore:ltsc2016
ARG FirefoxVersion
#if using powershell
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
RUN Write-Host Powershell: $env:FirefoxVersion
#if using CMD
SHELL ["cmd", "/S", "/C"]
RUN echo cmd.exe: %FirefoxVersion%

Build: docker build -t myimage --build-arg FirefoxVersion=61.0.1 .

Result

Powershell: 61.0.1
cmd.exe: 61.0.1

Try like this :

Pass arguments like ${FirefoxVersion}

ARG FirefoxVersion
RUN powershell -Command iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'));
RUN choco install -y firefox --version ${FirefoxVersion} --ignore-checksums

build docker image :

docker build -t --build-arg FirefoxVersion=61.0.1 myimage .
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!