ADD failed: file not found in build context or excluded by .dockerignore:

3.1k Views Asked by At

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

2

There are 2 best solutions below

0
On

I solved the problem by specifying relative path instead of absolute path.

My DockerFile and all other files were at "/root/files" directory and I was inside "/root/files" directory.

Earlier I had below statement in Dockerfile,

ADD --chown=abcuser:abc /root/files/patches.bom /opt/sbj/patches/patches.bom

which I changed to,

ADD --chown=abcuser:abc ./patches.bom /opt/sbj/patches/patches.bom

This worked.

0
On

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!