[英]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.