0

I have 3 different Docker images. I need to build these images from Jenkins file. I have Wildfly, Postgres, Virtuoso Docker images with individual Docker file. As of now, I am using the below command to build these images:

The directory structure is, Docker is the root diretory.

Docker->build->1. wildfly 2. postgres 3. virtuoso

In my jenkins file I have below command to build the image:

stage('Building test images')
{
   sh 'docker build -t virtuoso -f $WORKSPACE/build/virtuoso/Dockerfile .'
}

But I am getting error as below:

Step 7/16 : COPY ./install $VIRT_HOME/install
COPY failed: stat /var/lib/docker/tmp/docker-builder636357036/install: no such file or directory
[Pipeline] }

For reference below is my dockerfile:

FROM virtuoso:latest

ENV var1 /opt/virtuoso-opensource
ENV VIRT_db /opt/virtuoso-opensource/var/lib/virtuoso/db
ENV RUN_CONFIG=/opt/virtuoso-opensource/install/config

RUN export PATH=$PATH:/opt/virtuoso-opensource/bin

RUN mkdir $var1/install

COPY ./install $var1/install

WORKDIR $VIRT_db
CMD ["/opt/virtuoso-opensource/bin/init.sh"]

And the workspace is /home/jenkins/Docker and my guess is I am running docker build command from $workspace directory and this command should run from the virtuoso directory.

My question is how build image from Jenkins file?

Thanks in advance.

2 Answers 2

3

the easiest solution to solve this would be to enter the proper folder in the script before executing the docker build command. e.g.:

stage('Building test images') {
  steps {
    sh '''
      cd $WORKSPACE/build/virtuoso
      docker build -t virtuoso .
    ''' 
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

@Shanmukh please consider to accept the answer if it helped !
@LinPy ..... I consider to accept only those answers which works for me. Not every answer as comment.
1

Below is the answer:

stage('Build images'){
    echo "workspace directory is ${workspace}"
    dir ("$workspace/build/virtuoso")
    {
        sh 'docker build -t virtuoso -f $WORKSPACE/build/virtuoso/Dockerfile .'
    }
    dir ("$workspace/build/wildfly")
    {
        sh 'docker build -t wildfly -f $WORKSPACE/build/wildfly/Dockerfile .'
    }
    dir ("$workspace/build/postgres")
    {
        sh 'docker build -t postgres -f $WORKSPACE/build/postgres/Dockerfile .'
    }
}

Thanks for helping me out.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.