简体   繁体   English

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

[英]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.总的来说,我是编程的菜鸟,但 jenkins 更是如此。 I have a fastapi app and postgres as db, both running on distinct docker containers and a repo at github with the code.我有一个 fastapi 应用程序和 postgres 作为 db,它们都在不同的 docker 容器上运行,并且在 github 上有一个带有代码的仓库。 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. 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并让 jenkins 使用主机运行 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 .起初我在考虑使用 Docker-in-docker,以便 jenkins 实例位于可以运行 docker 的容器中,但由于这篇文章,我决定采用下面的方法。

So this is the jenkins istance:所以这是 jenkins 距离:

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.它已经与 github 集成,通过使用 github 应用程序,所以每次推送到 repo 时都会启动一个作业。

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 ?它不应该找到命令,因为它正在运行-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?而且,假设上述问题得到解决,jenkins 是否能够以这种方式构建和运行映像?

It turns out that mapping the sockets is not enough.事实证明,映射 sockets 是不够的。 I still need to have docker binary installed and in my case docker compose plugin as well.我仍然需要安装 docker 二进制文件,在我的情况下 docker 也需要安装插件。

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

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