Powershell 创建windows docker容器时出错

Powershell 创建windows docker容器时出错,powershell,docker,jboss,Powershell,Docker,Jboss,当我试图创建windows docker容器时,在设置路径时出现错误 我尝试过不同的方法但都失败了, 请建议与docker文件有关的问题。 我确信设置路径有问题 如果我没有添加系统路径,那么它将超越java、jboss路径 如何避免这个问题 PS C:\Users\rajen\Desktop\rajendar\Jboss> docker build -t oraclejdk:jboss . Sending build context to Docker daemon 866.7MB St

当我试图创建windows docker容器时,在设置路径时出现错误 我尝试过不同的方法但都失败了, 请建议与docker文件有关的问题。 我确信设置路径有问题 如果我没有添加系统路径,那么它将超越java、jboss路径 如何避免这个问题

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

我不构建Windows Docker容器,只构建Linux容器,所以我不知道您是否可以这样做。 但是,在使用该图像时,您将始终使用相同的路径,因此不需要使用%Path%。 您只需生成docker映像,查看默认路径,然后在docker文件中使用c:\jre1.8.045对其进行硬编码


干杯。

所以它不起作用的原因是,您要访问PowerShell,PowerShell的环境变量调用看起来与CMD的不同

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"

尝试运行setx/M路径“%PATH%;c:\jre1.8.0\u 45\bin”