1

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 :)

1
  • As written, the JAR file will be /root/app/app.jar/app.jar.
    – Raphael
    Commented Feb 28, 2019 at 14:07

2 Answers 2

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.