Search code examples
powershelldockerjboss

Getting error while creating windows docker container


when I am trying to create windows docker container , while setting the path I am getting error I have tried different ways but all tries are failed , please suggest issue with docker file. I am sure there is issue with setting path if I am not adding system path , it is over riding with java, jboss path how to avoid this issue

PS C:\Users\rajen\Desktop\rajendar\Jboss> docker build -t oraclejdk:jboss .
Sending build context to Docker daemon  866.7MB
Step 1/11 : FROM mcr.microsoft.com/windows/servercore:ltsc2016
 ---> c569a2ee6f10
Step 2/11 : SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
 ---> Using cache
 ---> 8e2560727f24
Step 3/11 : COPY jre1.8.0_45.zip c:\\jre1.8.0_45.zip
 ---> Using cache
 ---> 001334e133e0
Step 4/11 : COPY jboss-eap-7.0.zip c:\\jboss-eap-7.0.zip
 ---> Using cache
 ---> 1077fae7b3dd
Step 5/11 : RUN powershell Expand-Archive -Force c:\\jre1.8.0_45.zip c:
 ---> Using cache
 ---> caa85dc3383a
Step 6/11 : RUN powershell Expand-Archive -Force c:\\jboss-eap-7.0.zip c:
 ---> Using cache
 ---> 3901a7148b86
Step 7/11 : ENV JAVA_HOME "c:\jre1.8.0_45"
 ---> Using cache
 ---> 7a3b6cd69148
Step 8/11 : ENV JBOSS_HOME "c:\jboss-eap-7.0"
 ---> Using cache
 ---> b7c237b97158
Step 9/11 : RUN setx /M PATH "c:\jre1.8.0_45\bin;%PATH%"
 ---> Running in 285463042b56

SUCCESS: Specified value was saved.
%PATH% : The term '%PATH%' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:108
+ ... eference = 'SilentlyContinue'; setx /M PATH c:\jre1.8.0_45\bin;%PATH%
+                                                                    ~~~~~~
    + CategoryInfo          : ObjectNotFound: (%PATH%:String) [], ParentContai
   nsErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException

FROM mcr.microsoft.com/windows/servercore:ltsc2016

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]


COPY jre1.8.0_45.zip c:\\jre1.8.0_45.zip
COPY jboss-eap-7.0.zip c:\\jboss-eap-7.0.zip

RUN powershell Expand-Archive -Force c:\\jre1.8.0_45.zip c:
RUN powershell Expand-Archive -Force c:\\jboss-eap-7.0.zip c:
 
ENV JAVA_HOME "c:\jre1.8.0_45"
ENV JBOSS_HOME "c:\jboss-eap-7.0" 

#ENV path %path%";C:\jre1.8.0_45\bin;C:\jboss-eap-7.0\bin"
#RUN setx PATH "C:\jre1.8.0_45\bin;C:\jboss-eap-7.0\bin;%PATH%"
RUN setx /M PATH "c:\jre1.8.0_45\bin;%PATH%"

#CMD java -version

EXPOSE 8080/tcp
EXPOSE 9990/tcp
#CMD standalone.bat

Solution

  • So the reason it's not working, is because you set your shell form to PowerShell and PowerShell's environment variable calls look different than CMD's.

    FROM mcr.microsoft.com/windows/servercore:ltsc2016
    
    # This is where you're setting the form
    SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
    
    
    COPY jre1.8.0_45.zip c:\\jre1.8.0_45.zip
    COPY jboss-eap-7.0.zip c:\\jboss-eap-7.0.zip
    
    # Because you're already in powershell, you can simplify these
    #RUN powershell Expand-Archive -Force c:\\jre1.8.0_45.zip c:
    #RUN powershell Expand-Archive -Force c:\\jboss-eap-7.0.zip c:
    
    RUN Expand-Archive -Force c:\\jre1.8.0_45.zip c:
    RUN Expand-Archive -Force c:\\jboss-eap-7.0.zip c:
    
    
     
    ENV JAVA_HOME "c:\jre1.8.0_45"
    ENV JBOSS_HOME "c:\jboss-eap-7.0" 
    
    #ENV path %path%";C:\jre1.8.0_45\bin;C:\jboss-eap-7.0\bin"
    #RUN setx PATH "C:\jre1.8.0_45\bin;C:\jboss-eap-7.0\bin;%PATH%"
    
    # In PowerShell, instead of %PATH% you would use $env:Path
    # RUN setx /M PATH "c:\jre1.8.0_45\bin;%PATH%"
    
    RUN setx /M PATH "c:\jre1.8.0_45\bin;$env:Path"