docker - 如何使用Dockerfile的ARG指令获取Windows镜像

标签 docker dockerfile docker-for-windows

我想在我的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/

相关文章:

mysql - 构建 docker 容器后运行自定义 SQL 查询

docker - 在docker文件中安装python包

docker - 'docker -v' 绑定(bind)挂载在 Windows 10 上不再工作

docker - boot2docker/docker "Error. image library/.:latest not found"

docker - 在 Entrypoint 文件中导出环境变量不起作用?

docker - 尝试 ssh docker 容器时出错 : System is booting up

docker - 为什么 Windows docker 容器在 sleep 命令完成之前提前退出?

kubernetes - 安装 Helm 图表稳定/MSSQL的Linux我得到 “pod has unbound PersistentVolumeClaims”

docker - 一个 Docker 容器如何调用另一个 Docker 容器

docker - 有没有办法在 Dockerfile 中使用 If 条件?