问题描述
我想在dockerfile中传递一个参数来构建我的docker镜像。我在其他邮递员和docker手册中已经看到了如何执行此操作,但在我的情况下不起作用。
以下是我使用参数的代码摘录:
I would like to pass an argument in my dockerfile to build my docker image. I've seen in other post and docker manual how to do this but it doesn't work in my case.Here is an extract of my code where i use my argument:
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
I在powershellPrompt中使用此命令构建我的映像:
I build my image with this command in 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
有人知道我的代码有什么问题吗?
谢谢。
Is someone know what is wrong with my code?Thanks.
推荐答案
(此答案是我。)
尝试使用%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上,%...%
代表环境变量。
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.
这篇关于如何使用Dockerfile的ARG指令获取Windows映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!