【发布时间】:2017-04-02 12:20:27
【问题描述】:
我正在尝试使用运行 powershell 的 dockerfile 构建 docker 映像。嵌入的 powershell 脚本已经在 dockerfile 之外进行了测试,但是在运行 dockerfile 时出现错误。
来自 docker 文件:
RUN powershell -NoProfile -Command " \
$lines = (Get-Content c:\telegraf\telegraf.conf).replace('http://localhost:8086', 'http://publichost.com:8086'); \
Set-Content c:\telegraf\telegraf.conf $lines; \
$lines = (Get-Content c:\telegraf\telegraf.conf).replace('database = "telegraf"', 'database = "qa"'); \
Set-Content c:\telegraf\telegraf.conf $lines \
"
我收到以下错误:
At line:1 char:97
+ ... egraf.conf; $pos = [array]::indexof($lines, $lines -match global_ ...
+ ~
You must provide a value expression following the '-match' operator.
At line:1 char:97
+ ... egraf.conf; $pos = [array]::indexof($lines, $lines -match global_ ...
+ ~
Missing ')' in method call.
At line:1 char:98
+ ... $pos = [array]::indexof($lines, $lines -match global_tags); $ ...
+ ~~~~~~~~~~~
Unexpected token 'global_tags' in expression or statement.
At line:1 char:109
+ ... $pos = [array]::indexof($lines, $lines -match global_tags); $l ...
+ ~
Unexpected token ')' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : ExpectedValueExpression
脚本的目的是在配置文件的特定行添加新内容
知道语法有什么问题吗?
【问题讨论】:
-
我不知道 powershell,但看起来你的双引号字符串 inside 有双引号(特别是
...replace('database = "telegraf"'...),这通常不起作用. -
试过没有.. 相同的结果,它与我相信的 docker 文件语法有关
-
因为这种疯狂,我不再使用 dockerfile powershell 条目了。我将我所有的内容都放在 PS1 文件中,
COPY将它放入容器中并在其中执行。任何类型的 DSC 脚本等也是如此。请记住,dockerfile 中的每个Run命令都会为您的图像添加另一层,而带有一堆语句的单个 PS1 文件仍然是单层
标签: powershell docker dockerfile docker-for-windows windows-container