Issue while integrating Jenkins with Docker

Hi All,

I am trying to integrate one of my application using Jenkins and Docker. I have my code in github which after being compiled and tested I am creating a war file out of it and pushing the file in Docker registry. However I am failing at the last step where there is a Jenkins job to spawn a container out the war file using a tomcat image. I have written the following shell script:

sudo cd /root/docker/dockerfile
sudo docker build -f /root/docker/dockerfile/Dockerfile_AddressBook /root/docker/dockerfile -t garyhit1990/addressbook:$BUILD_NUMBER
sudo docker push garyhit1990/addressbook:$BUILD_NUMBER
sudo docker run -itd -P --name=addressbook:$BUILD_NUMBER garyhit1990/addressbook:$BUILD_NUMBER

However when I try building this job in Jenkins I am getting the following error(in BOLD):

Started by user unknown or anonymous
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/BuildDockerImage
[BuildDockerImage] $ /bin/sh -xe /tmp/jenkins3961484500090036544.sh

  • sudo cd /root/docker/dockerfile
  • sudo docker build -f /root/docker/dockerfile/Dockerfile_AddressBook /root/docker/dockerfile -t garyhit1990/addressbook:8
    Sending build context to Docker daemon 5.12kB

Step 1/3 : FROM tomcat
—> 6ab907c973d2
Step 2/3 : COPY /var/lib/jenkins/workspace/Package/target/addressbook.war /usr/local/tomcat/webapps
COPY failed: stat /var/lib/docker/tmp/docker-builder874098312/var/lib/jenkins/workspace/Package/target/addressbook.war: no such file or directory
Build step ‘Execute shell’ marked build as failure
Finished: FAILURE

The above error pops up when the DockerFile from which the container is spawned executes the followingcommands:

FROM tomcat
COPY addressbook.war /usr/local/tomcat/webapps
CMD [“catalina.sh”, “run”]

I tried giving the absolute path where the war file gets created in Jenkins target folder but it isn’t solving the issue. I am new to docker and have seen similar kind of issues but the solutions proposed are not resolving my issue. Would appreciate if someone can kindly help me solve this issue.