<p>It seems to me that your Dockerfile should be looking like this:</p>

<pre><code>FROM ~~container_on_private_registry~~
USER root
WORKDIR /root
ARG jenkins_jar_file=jenkins.jar
ENV jenkins_jar_file ${jenkins_jar_file}
RUN mkdir -p /root/app
COPY ${jenkins_jar_file} /root/app/app.jar
ENTRYPOINT ["java", "-jar", "/root/app/app.jar"]
</code></pre>

<p><strong>Explanation:</strong></p>

<p>We tell the Dockerfile to let Docker know, that it expects a variable named jenkins_jar_file to be passed to it during the build. Subsequent lines can reference that variable with a dollar notation.</p>

<p>Also when you build the image, use --no-cache so it will re-build all the layers of the image.</p>

CC BY-SA 4.0
2019-02-28T13:16:39.100Z
2019-02-28T13:16:39.100Z
Itai Ganot
<p>You can add one more step before running build and list the jars to ensure that this is the right jars then copy them to the place where is your Dockerfile and run the build </p>

CC BY-SA 4.0
2019-01-29T08:58:52.530Z
2019-01-29T08:58:52.530Z
Ahmed Badawy
<p>I am new to the DevOps world but I am trying to build a pipeline using Jenkins and Docker. </p>

<p>I have Jenkins building the docker image by:</p>

<pre><code>docker build -f Dockerfile --build-arg jenkins_jar_file=${JENKINS_JAR_FILE} -t ${DOCKER_IMAGE} .
</code></pre>

<p>Where JENKINS_JAR_FILE is a variable that points to the jar file produced by Jenkins</p>

<p>This is my Dockerfile:</p>

<pre><code>FROM ~~container_on_private_registry~~
USER root
WORKDIR /root
ARG jenkins_jar_file
RUN mkdir -p /root/app/app.jar
COPY ${jenkins_jar_file} /root/app/app.jar
ENTRYPOINT ["java", "-jar", "/root/app/app.jar"]
</code></pre>

<p>However, I feel like the image is not being built with the right JAR? 
I run docker images and see my image - but it says "Created 4 Days ago"
I see the same thing when I run docker images histroy for the entrypoint step. </p>

<p>When I actually try to run the image against a container, it for some odd reason tries to run against a jar which doesn't exist in the image. Instead it returns the following error:
/root/app-1.0-20180729.204127-14 </p>

<p>Any help appreaciated :)</p>

CC BY-SA 4.0
2019-02-28T14:07:12.410Z
As written, the JAR file will be `/root/app/app.jar/app.jar`.
Raphael
<docker><jenkins><dockerfile><java>
Docker build not picking up built jar?
Saiyam Sethi
# Docker build not picking up built jar?

(Asked by: username_0 on 2018-08-05)

I am new to the DevOps world but I am trying to build a pipeline using Jenkins and Docker. 
I have Jenkins building the docker image by:
docker build -f Dockerfile --build-arg jenkins_jar_file=${JENKINS_JAR_FILE} -t ${DOCKER_IMAGE} .

Where JENKINS_JAR_FILE is a variable that points to the jar file produced by Jenkins
This is my Dockerfile:
FROM ~~container_on_private_registry~~
USER root
WORKDIR /root
ARG jenkins_jar_file
RUN mkdir -p /root/app/app.jar
COPY ${jenkins_jar_file} /root/app/app.jar
ENTRYPOINT ["java", "-jar", "/root/app/app.jar"]

However, I feel like the image is not being built with the right JAR? 
I run docker images and see my image - but it says "Created 4 Days ago"
I see the same thing when I run docker images histroy for the entrypoint step. 
When I actually try to run the image against a container, it for some odd reason tries to run against a jar which doesn't exist in the image. Instead it returns the following error:
/root/app-1.0-20180729.204127-14 
Any help appreaciated :)

**Tags:** docker, jenkins, dockerfile, java

> **Comments:**
> **username_1**: As written, the JAR file will be `/root/app/app.jar/app.jar`.  

---

## 2 answers

### Answer by username_2 on 2019-02-28. Score: 1

It seems to me that your Dockerfile should be looking like this:
FROM ~~container_on_private_registry~~
USER root
WORKDIR /root
ARG jenkins_jar_file=jenkins.jar
ENV jenkins_jar_file ${jenkins_jar_file}
RUN mkdir -p /root/app
COPY ${jenkins_jar_file} /root/app/app.jar
ENTRYPOINT ["java", "-jar", "/root/app/app.jar"]

Explanation:
We tell the Dockerfile to let Docker know, that it expects a variable named jenkins_jar_file to be passed to it during the build. Subsequent lines can reference that variable with a dollar notation.
Also when you build the image, use --no-cache so it will re-build all the layers of the image.


---

### Answer by username_3 on 2019-01-29. Score: 0

You can add one more step before running build and list the jars to ensure that this is the right jars then copy them to the place where is your Dockerfile and run the build


---

