简体   繁体   中英

Can I use Jenkins on docker, integrate it to a private github repo and have jenkins use the host to run docker?

I am a noob in programming in general, but more even so with jenkins. I have a fastapi app and postgres as db, both running on distinct docker containers and a repo at github with the code. Now I am trying to use jenkins to automate tests every time I push new code to github, but I am thinking what I want to do is not really practical or possible, which is: use Jenkins on docker, integrate it to a private github repo and have jenkins use the host to run docker. At first I was thinking in using a Docker-in-docker so that the jenkins instance would be in a container that could run docker, but I decide to follow the approach bellow because of this article .

So this is the jenkins istance:

docker run -d --name jenkins-docker --restart=on-failure 
-v /var/run/docker.sock:/var/run/docker.sock -v jenkins_home:/var/jenkins_home 
-p 8080:8080 -p 5000:5000 jenkins/jenkins:lts-jdk11

and it is already integrated with github, through the use a github app, so every time a push to the repo a job starts.

Now, this is the jenkinsfile:

pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
         sh 'docker compose -p testing -f docker/testing.yml up -d'
      }
    }
  }
}

And this is the error:

/var/jenkins_home/workspace/vlep-pipeline_main@tmp/durable-9098aec0/script.sh: 1: docker: not found

Shouldn't it find the command since it is running with -v /var/run/docker.sock:/var/run/docker.sock ?

And, supposing the issue above is solved, would jenkins be able to build and run the images this way?

It turns out that mapping the sockets is not enough. I still need to have docker binary installed and in my case docker compose plugin as well.

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