1

This is my Dockerfile:

FROM openjdk:8
EXPOSE 8080
ADD target/springboot-example.jar springboot-example.jar
ENTRYPOINT ["java","-jar","/springboot-example.jar"]

While running docker build, I see this error:

Step 3/4 : ADD target/springboot-example.jar springboot-example.jar
ADD failed: file not found in build context or excluded by .dockerignore: stat target/springboot-example.jar: file does not exist

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
  • 1
    Are you sure you the file `target/springboot-example.jar` exists? It might have a different name, depending on how have configured the jar name generation E.g if you have the version built into the name before the `.jar`, you can use a wildcard: `ADD target/springboot-example*.jar springboot-example.jar` – Hans-Christian May 30 '22 at 16:32
  • Have you tried to specify a WORKDIR? – Jacobo May 31 '22 at 02:51

1 Answers1

0

In my case, the target file isn't match with pom.xml file.

Your target springboot-example is the (<artifactId>+<version>.jar) in pom.xml. I think springboot-example you declared in the dockerfile is doesn't match with artifactId and version tag in the pom.xml file. Just make sure your project with follow this step:

Step-1

go to the pom.xml file and make sure your <grupId> and <artifactId> its same with your Dockerfile target enter image description here

Step-2

Setting the Dockerfile, for my project it will be like this:

FROM openjdk:17
ADD target/intermnc-0.0.1.jar intermnc-0.0.1.jar
EXPOSE 8081
ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar intermnc-0.0.1.jar"]

Its SOLVED in my case, good luck dude!