簡體   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