0

I have the following in my Dockerfile:

# setup powershell
# Download the Microsoft repository GPG keys
RUN wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
# Register the Microsoft repository GPG keys
RUN dpkg -i packages-microsoft-prod.deb
# Update the list of products
RUN apt-get update && apt-get install -y \
    libunwind8 \
    libicu55 \
    powershell
# Register Powershell repo
RUN powershell Register-PSRepository ...

According to everything I have read, this should work, however I get the following output during docker build (censored with sensitive info).

Processing triggers for libc-bin (2.23-0ubuntu11) ...
Setting up liburcu4:amd64 (0.9.1-3) ...
Setting up liblttng-ust-ctl2:amd64 (2.7.1-1) ...
Setting up liblttng-ust0:amd64 (2.7.1-1) ...
Setting up powershell (7.0.0-1.ubuntu.16.04) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Removing intermediate container 1ef0413ecd13
 ---> a5323d6c8301
Step 12/23 : RUN powershell Register-PSRepository     ...<snip>...
 ---> Running in 604784872cc8
/bin/sh: 1: powershell: not found
The command '/bin/sh -c powershell Register-PSRepository ...<snip>... returned a non-zero code: 127

I am at a loss as to why powershell is not found bearing in mind that apt-get install call for it was successful.

How do invoke powershell after successfully installing it using apt-get?

2 Answers 2

1

After you install powershell, you should be able to call it using

pwsh

Sign up to request clarification or add additional context in comments.

Comments

1

As discovered from this blog, the executable changed name from 5.1 to 6.0 (aka Powershell Core): https://www.starwindsoftware.com/blog/using-powershell-on-linux

  • For Powershell v1.0 - 5.1 - powershell.exe on Windows
  • For Powershell v6.0+ - pwsh.exe on Windows, invoked as pwsh on MacOS and Linux

So the correct call is:

RUN pwsh -Command Register-PSRepository ... <etc>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.