我想在我的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
我在powershellPrompt中使用此命令构建镜像:
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
有人知道我的代码有什么问题吗?
谢谢。
最佳答案
(此答案是我的comment的正式版本。)
尝试使用%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
原因:
错误消息“命令'cmd/S/C choco install ...'返回的非零代码:1”表示
choco install
命令在cmd.exe(Windows命令提示符)上执行。 Dockerfile的ARG
值可以视为环境变量。在cmd.exe上,%...%
代表env var。
关于docker - 如何使用Dockerfile的ARG指令获取Windows镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53268105/