Does Jenkins Pipeline Plug-in support Docker Compose?

前端 未结 4 2140
深忆病人
深忆病人 2020-12-13 13:20

I\'m looking for a way to run Docker-enabled build consisting of multiple containers in Jenkins 2.0.

Are there any plans for native support of Docker Compose

相关标签:
4条回答
  • 2020-12-13 13:47

    After searching in Jenkins bug tracking, JENKINS-35025 suggests docker-compose.yml is taken into account when running a job in a docker container, using a maven build.

    See also Creating CI pipeline with Jenkins, which assumes docker-compose is installed on your Jenkins server.

    Note: a year later (August 2017), docker-compose is still not supported in the Docker Pipeline plugin

    July 2018, Ivan Aracki notes in the comments:

    Manually installing docker-cli and docker-compose with the same version as host's is the solution for now...

    0 讨论(0)
  • 2020-12-13 13:53

    Here are the files to run a jenkins container that runs docker inside:

    docker run \
      -p 8080:8080 \
      -v /var/run/docker.sock:/var/run/docker.sock \
      --name jenkins \
      getintodevops/jenkins-withdocker:lts
    

    reference: https://getintodevops.com/blog/the-simple-way-to-run-docker-in-docker-for-ci

    0 讨论(0)
  • 2020-12-13 13:59

    I am facing a similar problem, I found this https://reinout.vanrees.org/weblog/2017/10/03/docker-compose-in-jenkins.html but I do not know what is related to.

    My problem is test while developing, and also automate the test in Jenkins, and I am using docker-compose to bring up some php scripts AND a mysql server, to run isolated tests (phpunit as of now).

    I could think I can achieve this by

    1. creating a network in docker host (with docker network create)
    2. create and run a mysql docker attached to that network (with docker run mysql --network=netname --name=mysqlmachine
    3. run scripts by jenkins specifying --network and refering to mysqlmachine as host.

    But this would means I need to setup db data, cleanup db data, and also leave always on the mysqlmachine even when not needed, consuming some ram resource. I can solve last problem with docker start mysqlmachine and docker stop mysqlmachine command in my Jenkinsfile defining the pipeline.

    But, again, executing a shell into the docker where jenkins is running I can not find docker command

    For me is a viable solution untill I can not find something better

    UPDATE: I will try the https://wiki.jenkins.io/display/JENKINS/Docker+Slaves+Plugin solution, it has almost what I need

    UPDATE 08.02: as suggest by Alexander Zeitler, using

    agent {
            docker {
                image 'pdmlab/jenkins-node-docker-agent:6.11.1'
                args '-v /var/run/docker.sock:/var/run/docker.sock'
            }
        }
    

    in Jenkins file allow the use of docker-compose command: docker inside a docker, that is mostly docker near a docker as detailed here: Docker in Docker - volumes not working: Full of files in 1st level container, empty in 2nd tier

    But I preferred to use another approach, that does not require to run jenkins in a special way.

    The pipeline say:

    stage('Test') {
        steps {
            sh './build_docker.sh jenkinstests'
        }
    }
    

    and build_docker.sh does:

     jenkinstests)
     docker volume create idealodbconn
     docker run -v idealodbconn:/data --name helper busybox true
     docker cp ./dbconn/db249.json helper:/data
     docker rm helper
    
     docker-compose -f services/docker-compose-jenkins.yml up \
     --abort-on-container-exit \
     --exit-code-from idealoifapi
    
     docker-compose -f services/docker-compose-jenkins.yml rm -f
     docker volume rm idealodbconn
     ;;
    

    Also here --abort-on-container-exit say to exit once one container defined into docker-compose-jenkins.yml exits, and --exit-code-from idealoifapi says to take exit code from idealoifapi image.

    That is all. Missing part, maybe, is the docker-compose-jenkins.yml use of volume, it is external: true:

    volumes:
        idealodbconn:
            external: true
    
    0 讨论(0)
  • 2020-12-13 14:11

    I got docker-compose working in Jenkins pipelines using Nestybox, as described in their blog post. I built my Jenkins installation itself using the following Dockerfile:

    FROM nestybox/jenkins-syscont:latest
    # Install docker-compose
    RUN curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose \ 
    && chmod +x /usr/local/bin/docker-compose
    

    With that I simply followed the instructions in the blog post and can run pipelines that look something like this:

    pipeline {
    
       agent any
    
       stages {
           stage('docker-compose') {
               steps {
                  sh "docker-compose build"
                  sh "docker-compose up -d"
                  ...
               }
           }
       }
       post {
          always {
             sh "docker-compose down || true"
          }
       }   
    }
    
    0 讨论(0)
提交回复
热议问题