创建Windows Docker容器时出现错误

时间:2020-09-15 16:03:40

标签: powershell docker jboss

当我尝试创建Windows docker container时,设置路径时出现错误 我尝试了不同的方法,但是所有尝试都失败了, 请建议docker文件问题。 我确定设置路径有问题 如果我不添加系统路径,那就用java,jboss path结束 如何避免这个问题

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

2 个答案:

答案 0 :(得分:1)

所以它不起作用的原因是因为您set your shell form对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"

答案 1 :(得分:0)

我不构建Windows Docker容器,仅构建Linux容器,所以我不知道您是否可以这样做。 但是,使用该映像时,您将始终具有相同的Path,因此您无需使用%PATH%。 您可以只生成Docker映像,查看默认路径是什么,然后在Dockerfile中使用c:\​​ jre1.8.0_45对其进行硬编码。

干杯。