如何在我的计算机上建立Docker守护程序与Jenkins之间的连接以执行Docker命令?

huangapple go评论77阅读模式
英文:

How can i establish connection between docker daemon on my machine and Jenkins to execute docker commands?

问题

我的 Jenkins 文件:

pipeline {
   agent any

   stages {

      stage('初始化') {
         steps {
            script {
               def dockerHome = tool 'myDocker'
               env.PATH = "${dockerHome}/bin:${env.PATH}"
            }
         }
      }

      stage('构建') {
         steps {
            echo '构建后端...'
            withGradle() {
                sh './gradlew build'
            }
         }
      }

      stage('测试') {
         steps {
            echo '测试中'
         }
      }

      stage('部署') {
         steps {
            echo '部署中'
            sh './gradlew jibBuildTar'
            sh 'docker load --input build/image.tar'
         }
      }

   }
}

Jenkins 不允许我使用 docker 命令,因为 docker 守护程序未运行。我如何将我的守护程序连接到 Jenkins?我已经在 Jenkins 上安装了 docker 和 docker pipeline 插件。

英文:

My Jenkins file:

     pipeline {
       agent any

   stages {

     stage('Initialize') {
       steps {
         script {
           def dockerHome = tool 'myDocker'
           env.PATH = "${dockerHome}/bin:${env.PATH}"
         }
       }
     }


     stage('Build') {
       steps {
         echo 'building backend...'
         withGradle() {
             sh './gradlew build'
         }
       }
     }

     stage('Test') {
       steps {
         echo 'testing'
       }
     }

     stage('Deploy') {
       steps {
         echo 'deploying'
         sh './gradlew jibBuildTar'
         sh 'docker load --input build/image.tar'

       }
     }

   }
 }

Jenkins does not let me use docker command because docker daemon is not running. How can i connect my daemon to jenkins?
i Have docker and docker pipeline plugins installed on jenkins too.

答案1

得分: 1

总结讨论:

默认情况下,Jenkins 在 master 节点上执行。必须在 master 节点上安装 Docker,并且需要允许 Jenkins 用户执行 Docker 命令(应将其添加到 docker 用户组中)。

英文:

Sum up of discussion:

By default Jenkins executes on master node. Docker must be installed on master node and Jenkins user needs to be allowed to execute docker commands (should be added to docker group).

huangapple
  • 本文由 发表于 2020年4月6日 21:47:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/61061309.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定