简体   繁体   English

尝试使用docker运行jar时出现“无法访问jarfile”

[英]“Unable to access jarfile” when trying to run a jar with docker

I get Error: Unable to access jarfile jar-runner.jar when trying to run my jar. 我收到Error: Unable to access jarfile jar-runner.jar尝试运行jar时Error: Unable to access jarfile jar-runner.jar

Dockerfile: Dockerfile:

FROM anapsix/alpine-java
MAINTAINER bramhaag
CMD ["java", "-jar", "jar-runner.jar", "some param", "some param"]

The jar file is located in /home/selfbot/ and I'm running this with Portainer. jar文件位于/ home / selfbot /中,我正在使用Portainer运行它。 This is what my Portainer container looks like: 这是我的Portainer容器的外观: Portainer [1]

How would I make this work? 我将如何进行这项工作?

It looks like you have the volume mounted, so assuming that you are correct that the jar file is available in the container via that volume, you probably just need to specify the path to it so java can find it. 看起来好像已经安装了卷,因此假设您通过该卷在容器中可以使用jar文件是正确的,则可能只需要指定它的路径,以便Java可以找到它。

CMD ["java", "-jar", "/home/selfbot/jar-runner.jar", "some param", "some param"]

You can check whether the file is really available by running a different command to just show you the contents of a given directory. 您可以通过运行其他命令仅显示给定目录的内容来检查文件是否确实可用。 Change the command (in Portainer) to something like 将命令(在Portainer中)更改为类似

ls -la /home/selfbot

And then you can verify whether the jar file is actually where you think it, whether it is readable, etc. This command will exit right away, but its output will be available in the container log. 然后,您可以验证jar文件是否确实在您认为的位置,是否可读,等等。该命令将立即退出,但其输出将在容器日志中可用。

Try 尝试
ENTRYPOINT ["java","-jar","jar-runner.jar"] CMD ["some param"]

I had a similar issue here on my post: Error: Unable to access jarfile when running docker container 我的帖子在这里有类似的问题: 错误:运行docker容器时无法访问jarfile

With CMD [ ] "exec" format, Docker will try to look at the arguments and give its opinion about their usefulness. 使用CMD [ ] “ exec”格式,Docker将尝试查看参数并给出其有用性的意见。 "Unable to access jarfile" is a Docker message, and it just means Docker has some (unspecified) issues with a jarfile. “无法访问jarfile”是Docker消息,它仅表示Docker的jarfile存在一些(未指定)问题。 I've encountered it when the name of the jarfile contained an ENV variable, for instance. 例如,当jarfile的名称包含ENV变量时,我就遇到了它。 Docker couldn't handle that, apparently. 显然,Docker无法解决这一问题。

There's also the CMD "shell" format, CMD java -jar jar-runner.jar "some param" "some param" . 还有CMD “ shell”格式, CMD java -jar jar-runner.jar "some param" "some param" This is known as the shell format because Docker hands of the arguments to /bin/sh -c . 这被称为shell格式,因为Docker会将/bin/sh -c的参数传递给他们。 As a result, it's not trying to second-guess what the arguments mean. 结果,它不会试图对参数的含义进行猜测。 sh in turn doesn't try to be smart either. 反过来, sh也不会尝试变得聪明。 And java is entirely capable of using jar-runner.jar . java完全可以使用jar-runner.jar

Mind you, if you've got a typo in jar-runner.jar , or you put it in the wrong location, then Docker's message might be right. 请注意,如果您在jar-runner.jar中输入错误,或者将其放在错误的位置,那么Doc​​ker的信息可能是正确的。 The shell workaround is useful when Docker guesses wrong. 当Docker猜错时,shell解决方法很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM