linuxspring-bootdockerrhel

powershell needed for a springboot project dependency


Hi So im working a project where a springboot project uses a maven dependency jpowershell

Now my problem is i have dockerized the project with a rhel 7 base image and also installing powershell and trying to run my docker image but get the error and the docker container exits

PowerShell not available com.profesorfalken.jpowershell.PowerShellNotAvailableException: Cannot execute PowerShell.exe. Please make sure that it is installed in your system

This is my docker file ,am following the correct procedure or am i making some mistake .Any help will be much appreciated

FROM something.abc.com/test-base/rhel:7

ENV http_proxy http://http.proxy.xyz.com:8000
ENV https_proxy http://http.proxy.xyz.com:8000
ENV no_proxy localhost,127.0.0.1,.xyz.com
ENV PATH="/usr/java/jdk-15.0.1/bin:$PATH"

# Install common packages

RUN yum install -y bzip2
RUN yum install -y wget
RUN wget https://github.com/PowerShell/PowerShell/releases/download/v7.3.7/powershell-7.3.7-1.rh.x86_64.rpm
RUN yum install -y powershell-7.3.7-1.rh.x86_64.rpm
RUN pwsh --version


# Download and Install OpenJDK 15

RUN cd /tmp && wget https://download.java.net/java/GA/jdk15.0.1/51f4f36ad4ef43e39d0dfdbaf6549e32/9/GPL/openjdk-15.0.1_linux-x64_bin.tar.gz && \
    tar -xvzf openjdk-15.0.1_linux-x64_bin.tar.gz && \
    mkdir -p /usr/java && mv /tmp/jdk-15.0.1 /usr/java


VOLUME /tmp
ADD target/xyz-*.jar /app/xyz/sample.jar

EXPOSE 8080
ENTRYPOINT ["java","-jar","/app/xyz/sample.jar"]

This is the error when i run the docker container enter image description here

Powershell paths enter image description here

enter image description here


Solution

  • As outlined in the powershell docs after Powershell 5.1:

    The binary name for PowerShell has been changed from powershell(.exe) to pwsh(.exe)

    jPowershell is looking for a binary called powershell which will not work in your environment.

    One possible solution is changing the executable name jPowershell is looking for (as described here):

    //Creates PowerShell session
    try (PowerShell powerShell = PowerShell.openSession("pwsh")) {
       ...
    }