简体   繁体   English

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

[英]Why does my docker build fail on jenkins agent?

Here is my Jenkinsfile pipeline in a project 这是我在项目中的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'
            }
        }
    }
}

And I have a jenkins master and slave agent respectively. 我分别有一个詹金斯主代理和从代理。 The above pipeline works well in master node, but if run in a slave agent node, then it would met the following error: 上面的管道在主节点上运行良好,但是如果在从代理节点上运行,则会遇到以下错误:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I am pretty sure that docker is running on the agent node because I can ssh to it and run docker commands successfully. 我非常确定docker正在代理节点上运行,因为我可以使用ssh并成功运行docker命令。

Why it behaves differently between running on master and slave agent? 为什么在主代理和从代理上运行时其行为不同? How should I fix it? 我应该如何解决? Thanks very much! 非常感谢!

I don't know why but I fixed it with the following change: appened -v /var/run/docker.sock:/var/run/docker.sock to args. 我不知道为什么,但是我通过以下更改对其进行了修复:将-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'
            }
        }
    }
}

暂无
暂无

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

相关问题 为什么我的Docker项目的“继续构建”失败了? - Why does “go build” fail for my Docker project? 为什么Maven Surefire 3无法在Docker的Jenkins中运行我的Cucumber测试? - Why does Maven Surefire 3 fail to run my Cucumber test in Jenkins with Docker? 为什么 FROM registry.hub.docker.com/library/centos:centos7 在我的 docker 构建中失败? - Why does FROM registry.hub.docker.com/library/centos:centos7 fail in my docker build? 当我的 dotnet 测试在 Docker 构建中失败时,如何将测试报告从 docker 复制到代理? - How do I copy test report from docker to Agent when my dotnet tests fail in Docker Build? 为什么在运行“docker build”时我的 maven 依赖项获取失败并重置连接? - Why does my maven dependency fetching fail with a connection reset when running `docker build`? 在Jenkins中构建Docker映像(在Docker映像中)-Cloud Docker Agent - Build Docker image in Jenkins (in Docker image) - Cloud docker agent 为什么 docker 构建失败:无法解析 Dockerfile:没有说明的文件 - Why does docker build fail with: failed to parse Dockerfile: file with no instructions 在 Jenkins Docker 代理中使用测试容器:容器无法启动,NoRouteToHostException - Using testcontainers in a Jenkins Docker Agent: containers fail to start, NoRouteToHostException 获取 docker:Jenkins docker 构建代理中的无效参考格式 - Getting docker: invalid reference format in Jenkins docker build agent Jenkins 构建代理 docker 指定 docker 文件名 - Jenkins build agent docker specify docker file name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM