'Docker jar not found
My docker file looks like this:
FROM openjdk:9
VOLUME /tmp
ADD target/myjar-1.0-SNAPSHOT.jar app.jar
ENTRYPOINT [“java”,”-jar”,”/app.jar”]
When I run docker build -t myjar it builds fine.
When I run docker run image I get this error:
/bin/sh: 1: [“java”,”-jar”,”/app.jar”]: not found
I heard this could be a "relative path" issue? I'm not sure how to fix it or where the jar should even reside. I need help debugging this.
Solution 1:[1]
Ensure that you ADD your jar at the root using:
ADD target/myjar-1.0-SNAPSHOT.jar /app.jar
Additionally, if you don't override the command when you start your image, use CMD (documentation) instead of ENTRYPOINT (and also try to use more "normal" quotes instead of ”):
CMD ["java", "-jar", "/app.jar"]
EDIT:
Are you sure you're using double quotes ?
EDIT 2:
Try without brackets:
CMD java -jar /app.jar
Solution 2:[2]
Please do remember, docker container internal is a Linux (or similar kind of) environment. While we are running the below command on windows command prompt(C:/>) it is missing bash shell
docker container commit --change='CMD ["java","-jar","/tmp/hello-world-rest-api.jar"]' boring_archimedes advanceinfo/hello-world-rest-api:manual2
So, we are getting below error
/bin/sh: [java,-jar,/tmp/hello-world-rest-api.jar]: not found
Please use one command prompt in windows which support bash shell example Git Bash prompt($) Note: don't change the above command, only change the command prompt, it will work 1000%
Solution 3:[3]
You can change the ADD instruction to an absolute path:
ADD target/myjar-1.0-SNAPSHOT.jar /app.jar
Solution 4:[4]
Solution 5:[5]
This Error occurs only in Windows 10 . Use below command
$> docker container commit --change='CMD java -jar /tmp/app-name.jar' <container_name> <docker_registry>/app-name:
Solution 6:[6]
I was getting below error : docker : /bin/sh: [java,-jar,/tmp/hello-world-rest-api.jar]: not found Below commit resolved my issue in windows 10 : docker container commit --change='CMD java -jar /tmp/hello-world-rest- api.jar' kind_hermann in28min/hello-world-rest-api:singraul-3 For Linux machine : docker container commit --change='CMD ["java","-jar","/tmp/hello-world-rest- api.jar"]' kind_hermann in28min/hello-world-rest-api:singraul-2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Swadhin Lenka |
| Solution 3 | yamenk |
| Solution 4 | Ganesh Giri |
| Solution 5 | vinod kumar |
| Solution 6 | Devendra Singraul |
