Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Unable to access jarfile" when trying to run a jar with docker

Tags:

java

docker

jar

I get Error: Unable to access jarfile jar-runner.jar when trying to run my jar.

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. This is what my Portainer container looks like: Portainer[1]

How would I make this work?

like image 750
bramhaag Avatar asked Dec 04 '25 04:12

bramhaag


1 Answers

With CMD [ ] "exec" format, Docker will try to look at the arguments and give its opinion about their usefulness. "Unable to access jarfile" is a Docker message, and it just means Docker has some (unspecified) issues with a jarfile. I've encountered it when the name of the jarfile contained an ENV variable, for instance. Docker couldn't handle that, apparently.

There's also the CMD "shell" format, 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. As a result, it's not trying to second-guess what the arguments mean. sh in turn doesn't try to be smart either. And java is entirely capable of using 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. The shell workaround is useful when Docker guesses wrong.

like image 159
MSalters Avatar answered Dec 05 '25 18:12

MSalters