简体   繁体   English

如何从 jenkinsfile 构建多个 docker 容器?

[英]How to build multiple docker containers from jenkinsfile?

I have 3 different Docker images.我有 3 个不同的 Docker 图像。 I need to build these images from Jenkins file.我需要从 Jenkins 文件构建这些图像。 I have Wildfly, Postgres, Virtuoso Docker images with individual Docker file.我有 Wildfly、Postgres、Virtuoso Docker 图像和单独的 Docker 文件。 As of now, I am using the below command to build these images:到目前为止,我正在使用以下命令来构建这些图像:

The directory structure is, Docker is the root diretory.目录结构为,Docker为根目录。

Docker->build->1.码头工人->构建-> 1。 wildfly 2. postgres 3. virtuoso wildfly 2. postgres 3. virtuoso

In my jenkins file I have below command to build the image:在我的 jenkins 文件中,我有以下命令来构建映像:

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:以下是我的 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.工作区是 /home/jenkins/Docker ,我猜我正在从 $workspace 目录运行 docker 构建命令,这个命令应该从 virtuoso 目录运行。

My question is how build image from Jenkins file?我的问题是如何从 Jenkins 文件构建图像?

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.解决此问题的最简单解决方案是在执行docker build命令之前在脚本中输入正确的文件夹。 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.谢谢你的协助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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