简体   繁体   中英

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.

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

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%

您可以将ADD指令更改为绝对路径:

ADD target/myjar-1.0-SNAPSHOT.jar /app.jar

I Have solved this using the following command:

CMD exec java -jar "$FINALNAME"

More detail here

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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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