简体   繁体   中英

How to build multiple docker containers from jenkinsfile?

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.

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM