Dockerfile运行管道式powershell
我的Dockerfile包含以下行Dockerfile运行管道式powershell,docker,powershell,dockerfile,Docker,Powershell,Dockerfile,我的Dockerfile包含以下行 RUN pwsh -Command Find-Module deployment.aws.applications -AllVersions | Where-Object {[version]$_.Version -ge '5.1.10' -and [version]$_.Version -le '100.0.0'} | ForEach-Object { Install-Module -Name $_.Name -RequiredVersion $_.Vers
RUN pwsh -Command Find-Module deployment.aws.applications -AllVersions | Where-Object {[version]$_.Version -ge '5.1.10' -and [version]$_.Version -le '100.0.0'} | ForEach-Object { Install-Module -Name $_.Name -RequiredVersion $_.Version -Repository ${REPOSITORY} -Scope AllUsers -AcceptLicense -Force }
哪些产出:
=> [2/2] RUN pwsh -Command Find-Module deployment.aws.applications -AllVersions | Where-Object {[version]$_.Version -ge '5.1.10' -and [version]$_.Version -le '100.0.0'} | ForEach-Object { Install-Module -Name $_.Name -Required 14.0s
=> => # /bin/sh: 1: ForEach-Object: not found
=> => # /bin/sh: 1: Where-Object: not found
看起来正在发生的是管道(|)没有被视为Powershell命令。我用引号将整行括起来,但是Dockerfile参数没有得到解决
为了使整个问题更加复杂,我想通过one-Dockerfile-run命令运行多个Powershell命令。像这样:
RUN pwsh -Command Find-Module deployment.aws.applications -AllVersions | Where-Object {[version]$_.Version -ge '5.1.10' -and [version]$_.Version -le '100.0.0'} | ForEach-Object { Install-Module -Name $_.Name -RequiredVersion $_.Version -Repository ${REPOSITORY} -Scope AllUsers -AcceptLicense -Force } && \
pwsh -Command Find-Module x.y.z -AllVersions | Where-Object {[version]$_.Version -ge '5.1.10' -and [version]$_.Version -le '100.0.0'} | ForEach-Object { Install-Module -Name $_.Name -RequiredVersion $_.Version -Repository ${REPOSITORY} -Scope AllUsers -AcceptLicense -Force }
如果您的Powershell命令变得越来越复杂,那么将它们放入脚本中并使用
RUN
来执行该脚本会更容易
查找安装模块.ps1
Find-Module deployment.aws.applications -AllVersions | Where-Object {[version]$_.Version -ge '5.1.10' -and [version]$_.Version -le '100.0.0'} | ForEach-Object { Install-Module -Name $_.Name -RequiredVersion $_.Version -Repository ${REPOSITORY} -Scope AllUsers -AcceptLicense -Force }
Dockerfile
ADD Find-Install-Modules.ps1 .
RUN pwsh -File Find-Install-Modules.ps1