为什么此docker映像会返回此错误:无法访问jarfile /home/server.jar

时间:2018-12-19 10:58:19

标签: docker

FROM "this line works but cant show code"

RUN yum install -y java-1.8.0-openjdk.x86_64  && yum clean all
COPY /resources/accounts.txt /home/resources/accounts.txt
COPY elk_casino_server /home/elk_casino_server
CMD ["jar","cvmf","/home/elk_casino_server/src/META-INF/MANIFEST.MF","/home/server.jar","/home/elk_casino_server/src/Main.class"]
CMD ["java","-jar","/home/server.jar"]

2 个答案:

答案 0 :(得分:0)

请花一些时间来正确设置代码段的格式,并确保您提出明确的问题。

您的Dockerfile使用COPY指令将两个资源复制到您的容器映像中:

  1. /resources/accounts.txt(在图像中位于/home/resources/accounts.txt上)
  2. /elk_casino_server(在图像中位于/home/elk_casino_server上)

很遗憾,您的CMD指令试图执行截然不同的操作。只能定义一个命令指令,而后者将被接受,即:

CMD ["java","-jar","/home/server.jar"]

您永远不会将/home/server.jar复制到您的容器映像中。

答案 1 :(得分:0)

The parameter order of the char command seems to be wrong. The manifest-addition should come after the jar-file, not before it.

jar cfm jar-file manifest-addition input-file(s)

see: Packaging Programs in JAR Files: Modifying a Manifest File


Also: If there are more than one CMD, the last one overrides the others. Since I think you want to pack the jar at build time, RUN might be a better choice.


Both points combined:

RUN jar cvmf /home/server.jar /home/elk_casino_server/src/META-INF/MANIFEST.MF /home/elk_casino_server/src/Main.class