繁体   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?

总的来说,我是编程的菜鸟,但 jenkins 更是如此。 我有一个 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并让 jenkins 使用主机运行 docker。 起初我在考虑使用 Docker-in-docker,以便 jenkins 实例位于可以运行 docker 的容器中,但由于这篇文章,我决定采用下面的方法。

所以这是 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

它已经与 github 集成,通过使用 github 应用程序,所以每次推送到 repo 时都会启动一个作业。

现在,这是詹金斯文件:

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

这是错误:

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

它不应该找到命令,因为它正在运行-v /var/run/docker.sock:/var/run/docker.sock吗?

而且,假设上述问题得到解决,jenkins 是否能够以这种方式构建和运行映像?

事实证明,映射 sockets 是不够的。 我仍然需要安装 docker 二进制文件,在我的情况下 docker 也需要安装插件。

暂无
暂无

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

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