Powershell: Can't use pwsh commands inside Windows container build

Created on 19 Jan 2018  路  5Comments  路  Source: PowerShell/PowerShell

Steps to reproduce

Create a minimal Dockerfile with the following:

FROM microsoft/powershell:6.0.0-nanoserver-1709
SHELL ["pwsh"]
RUN Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/v4.5.0/nuget.exe" -OutFile nuget.exe

Expected behavior

The file downloads just fine and is available inside container.

Actual behavior

The argument 'Invoke-WebRequest' is not recognized as the name of a script file. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Note that when I run docker run -it microsoft/powershell:6.0.0-nanoserver-1709 and then execute the Invoke-WebRequest, all is fine.

Issue-Question

Most helpful comment

Verified that the docker build is successful with the change suggested by @pcgeek86

Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM microsoft/powershell:6.0.0-nanoserver-1709
6.0.0-nanoserver-1709: Pulling from microsoft/powershell
407ada6e90de: Already exists
711a33cda32c: Pull complete
5f5589a467e5: Pull complete
d50558d94b1e: Pull complete
376b8d293962: Pull complete
b4c4521a1951: Pull complete
6a9fca0fbefe: Pull complete
7bf29c6a0e4f: Pull complete
3bef1c441b8f: Pull complete
83220a6ead00: Pull complete
ab070f6e164f: Pull complete
Digest: sha256:b5359ee98bcbc7c88da4eaa297265a3b27c9c9deb762e270241c8214524849ea
Status: Downloaded newer image for microsoft/powershell:6.0.0-nanoserver-1709
 ---> 29a006b326ce
Step 2/3 : SHELL pwsh -Command
 ---> Running in 2d250e6be3a3
 ---> fa26c756533a
Removing intermediate container 2d250e6be3a3
Step 3/3 : RUN Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/v4.5.0/nuget.exe" -OutFile nuget.exe
 ---> Running in 926cb4362fc2
 ---> cf3d2ccfa996
Removing intermediate container 926cb4362fc2
Successfully built cf3d2ccfa996

Hence, I will close this issue.

All 5 comments

FROM microsoft/powershell:6.0.0-nanoserver-1709
SHELL ["pwsh", "-Command"]
RUN Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/v4.5.0/nuget.exe" -OutFile nuget.exe

@bloodybeet pwsh uses -File flag by default. You need to specify -Command if you want to run a script string directly.

Note that this was actually a change from Windows PowerShell. Using Windows PowerShell (Desktop Edition), you can simply specify a command after the executable name. However, this was changed in PowerShell Core to act more like Bash, as I understand it.

screen shot 2018-01-19 at 9 36 40 am

Verified that the docker build is successful with the change suggested by @pcgeek86

Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM microsoft/powershell:6.0.0-nanoserver-1709
6.0.0-nanoserver-1709: Pulling from microsoft/powershell
407ada6e90de: Already exists
711a33cda32c: Pull complete
5f5589a467e5: Pull complete
d50558d94b1e: Pull complete
376b8d293962: Pull complete
b4c4521a1951: Pull complete
6a9fca0fbefe: Pull complete
7bf29c6a0e4f: Pull complete
3bef1c441b8f: Pull complete
83220a6ead00: Pull complete
ab070f6e164f: Pull complete
Digest: sha256:b5359ee98bcbc7c88da4eaa297265a3b27c9c9deb762e270241c8214524849ea
Status: Downloaded newer image for microsoft/powershell:6.0.0-nanoserver-1709
 ---> 29a006b326ce
Step 2/3 : SHELL pwsh -Command
 ---> Running in 2d250e6be3a3
 ---> fa26c756533a
Removing intermediate container 2d250e6be3a3
Step 3/3 : RUN Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/v4.5.0/nuget.exe" -OutFile nuget.exe
 ---> Running in 926cb4362fc2
 ---> cf3d2ccfa996
Removing intermediate container 926cb4362fc2
Successfully built cf3d2ccfa996

Hence, I will close this issue.

Thanks guys :) !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JohnLBevan picture JohnLBevan  路  3Comments

andschwa picture andschwa  路  3Comments

lzybkr picture lzybkr  路  3Comments

garegin16 picture garegin16  路  3Comments

Michal-Ziemba picture Michal-Ziemba  路  3Comments