docker - 如何使用 Dockerfile for Windows 镜像的 ARG 指令
问题描述
我想在我的 dockerfile 中传递一个参数来构建我的 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
有人知道我的代码有什么问题吗?谢谢。
解决方案
正如@matt9 建议的那样
$env:FirefoxVersion
在 powershell 中使用
%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%
建造:docker build -t myimage --build-arg FirefoxVersion=61.0.1 .
结果
Powershell: 61.0.1
cmd.exe: 61.0.1
推荐阅读
- android - Android Emulator Don't Run My Apps and show me Android SDK built for x86 64(mobile) 而不是我的模拟器名称
- python - python numpy矩阵逐行操作:每行中的列
- java - MOOC 运动统计 - 一个字符串在文件中出现多少次?
- javascript - 在 JavaScript 中,为什么 super 关键字不总是调用父类方法以进行进一步调用?
- node.js - 从 Node.js 中的动画 GIF 获取正确的调色板
- python - 如何在kivy中的应用程序文件中保存和加载设置?
- sql - 如何在 SQL 中获得两个表的并集
- java - Java 是 OOP 语言。我们可以通过创建对象来调用它,也可以像 POP 一样使用它。但这有什么问题呢?
- google-cloud-platform - GCP 上的 WordPress 实例上的 HTTPS 连接被拒绝
- c# - Xamarin 错误:找不到所引用的对象