我想在 dockerfile 中传递一个参数来构建我的 docker 映像。我在其他帖子和 Docker 手册中看到了如何执行此操作,但在我的情况下不起作用。
这是我使用我的论点的代码摘录:
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
我在 powershell Prompt 中使用此命令构建图像:
docker build -t myimage --build-arg FirefoxVersion=61.0.1 .
最后我有这个错误:
'$FirefoxVersion' is not a valid version string.
Parameter name: version
The command 'cmd /S /C choco install -y firefox --version $FirefoxVersion -- ignore-checksums' returned a non-zero code: 1
有人知道我的代码有什么问题吗?
谢谢。
正如@matt9建议的
Use $env:FirefoxVersion
在 powershell 中
Use %FirefoxVersion%
在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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)