这是我的文档文件:
# Start with a base image containing Java runtime
FROM openjdk:8-jdk-alpine
# Add a volume pointing to /tmp
VOLUME /tmp
# Make port 8080 available to the world outside this container
EXPOSE 8080
# The application's jar file
COPY Server_Changes/glowroot /tmp
ARG JAR_FILE=target/websocket-demo-0.0.1-SNAPSHOT.jar
ARG OK=/tmp/glowroot.jar
# Add the application's jar to the container
ADD ${JAR_FILE} websocket-demo.jar
# Run the jar file
ENTRYPOINT ["java", " -javaagent:/glowroot.jar" , "- Dglowroot.agent.id=Docker "," -jar /websocket-demo.jar"]
构建图像时出现以下错误:
Could not find or load main class-javaagent:.glowroot.jar
有人可以解释一下为什么吗?
最佳答案
当您在 RUN
中使用类似 JSON 的语法时, ENTRYPOINT
,和CMD
命令,引号内的空格很重要。特别是,当你说
ENTRYPOINT ["java", " -javaagent:/glowroot.jar" , ...]
# ^
空格是选项的一部分;并且由于该选项不以 -
开头,Java将其解释为类名。这基本上适用于您的所有选择。在最后一个选项中,-jar
类名是两个单独的选项,并且需要位于两个单独的“单词”中。
(考虑将 ENTRYPOINT
更改为 CMD
以使图像更易于调试,并删除 VOLUME
声明;它只会导致意外的奇怪副作用。)
CMD ["java", "-javaagent:/glowroot.jar",
"-Dglowroot.agent.id=Docker",
"-jar", "/websocket-demo.jar"]
关于java - 从 docker 文件传递 jvm 参数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55892102/