docker - 为什么我的Docker构建无法在jenkins代理上失败?

标签 docker jenkins-pipeline

这是我在项目中的Jenkinsfile管道

pipeline {
    agent {
        docker {
            image 'docker:dind'
            args '-u root:root -p 3000:3000 --privileged'
        }
    }

    environment {
        CI = 'true'
    }

    stages {
        stage('docker build') {
            when {
                branch 'master'
            }
            steps {
                sh 'docker build --label v1.0.0 -t myrepo/myapp:v1.0.0'
            }
        }
    }
}

我分别有一个 Jenkins 主代理和从代理。上面的管道在主节点上运行良好,但是如果在从代理节点上运行,则会遇到以下错误:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

我非常确定docker正在代理节点上运行,因为我可以使用ssh并成功运行docker命令。

为什么在主代理和从代理上运行时它的行为有所不同?我该如何解决?非常感谢!

最佳答案

我不知道为什么,但是我通过以下更改对其进行了修复:将-v /var/run/docker.sock:/var/run/docker.sock应用于args。

pipeline {
    agent {
        docker {
            image 'docker:dind'
            args '-u root:root -p 3000:3000 --privileged -v /var/run/docker.sock:/var/run/docker.sock'
        }
    }

    environment {
        CI = 'true'
    }

    stages {
        stage('docker build') {
            when {
                branch 'master'
            }
            steps {
                sh 'docker build --label v1.0.0 -t myrepo/myapp:v1.0.0'
            }
        }
    }
}

关于docker - 为什么我的Docker构建无法在jenkins代理上失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52826971/

相关文章:

docker - Jenkins Pipeline 和 Docker - 如何从容器归档文件

jenkins - 如何使用 Pipeline Job 的 CopyArtifact 插件传递从中复制工件的内部版本号?

c# - Jenkins REST API 获取作业和作业控制台日志

git - 从 Jenkins 管道捕获 shell 脚本输出

docker - HNS 失败,错误为 : The parameter is incorrect

docker - Kubernetes集群上的Apache pulsar(本地环境)

node.js - 在 Windows 上找不到 monax 命令

php - Docker-Compose Wordpress:wp_mail()不起作用

docker - 为什么eclipse-temurin官方没有OpenJ9 docker镜像

Jenkinsfile 管道错误 : “expected a step” and “undefined section”