Reputation: 47
My Dockerfile contains the following line
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 }
Which outputs:
=> [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
What looks to be happening is the pipe (|) isn't being seen as a Powershell command. I had wrapped the whole line in quotes, but the Dockerfile args don't get resolved.
To make the whole issue a little more complex, I then want to run mutiple Powershell commands via the one Dockerfile RUN command. Like so:
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 }
Upvotes: 0
Views: 290
Reputation: 19164
If your Powershell commands are becoming complex, it would be easier to put them into a script and just use RUN
to execute that script.
Find-Install-Modules.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
Upvotes: 1