Reputation: 81
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.
Upvotes: 4
Views: 9131
Reputation: 28800
To add to Paul Rey's answer. I experienced a similar issue when trying to deploy a Java application:
This was my Dockerfile
:
FROM openjdk:8-jre
VOLUME /tmp
WORKDIR /app
COPY payment-collection.jks .
RUN cat /app/payment.jks
RUN keytool -list -v -keystore /app/payment.jks -storepass my-name.
RUN mkdir cert
COPY payment.jks /app/cert
COPY /target/payment-1.0.1-SNAPSHOT.jar /app
ENTRYPOINT [\"java\",\"-jar\",\"/app/${prod_jar_name}.jar\"]
EXPOSE 443
But when I deploy the docker app, I get the error:
/bin/sh: 1: ["java","-jar","/app/payment-1.0.1-SNAPSHOT.jar"]: not found
Here's how I fixed it:
I simply changed from this:
ENTRYPOINT [\"java\",\"-jar\",\"/app/payment-1.0.1-SNAPSHOT.jar\"]
To this:
ENTRYPOINT ["java", "-jar", "/app/payment-1.0.1-SNAPSHOT.jar"]
So my new Dockerfile
looked like this after then:
FROM openjdk:8-jre
VOLUME /tmp
WORKDIR /app
COPY payment-collection.jks .
RUN cat /app/payment.jks
RUN keytool -list -v -keystore /app/payment.jks -storepass my-name.
RUN mkdir cert
COPY payment.jks /app/cert
COPY /target/payment-1.0.1-SNAPSHOT.jar /app
ENTRYPOINT ["java", "-jar", "/app/payment-1.0.1-SNAPSHOT.jar"]
EXPOSE 443
Upvotes: 0
Reputation: 951
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
Upvotes: 0
Reputation: 25
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%
Upvotes: 2
Reputation: 41
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:
Upvotes: 3
Reputation: 1151
I Have solved this using the following command:
CMD exec java -jar "$FINALNAME"
More detail here
Upvotes: 0
Reputation: 1337
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
Upvotes: 2
Reputation: 51758
You can change the ADD
instruction to an absolute path:
ADD target/myjar-1.0-SNAPSHOT.jar /app.jar
Upvotes: 0