我正在关注Jenkins网站上的官方tutorial。我有一个blueocean Docker容器,根据教程在Jenkinsfile
运行管道:
pipeline {
agent {
docker {
image 'node:6-alpine'
args '-p 3000:3000'
}
}
stages {
stage('Build') {
steps {
sh 'npm install'
}
}
}
}
问题是当管道尝试拉出Docker镜像时管道失败:
[ode-js-react-npm-app_master-6PEWX3VWDA4SAdDMJA4YKJCZSABJSAQCSGVYMKHINXGDDJLA] Running shell script
+ docker pull node:6-alpine
Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon. Is the docker daemon running on this host?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
script returned exit code 1
经过一些故障排除后,我意识到这是失败的,因为Jenkins试图拉动Docker容器本身,而不是主机。这不是我想要的,文档实际上说明了:
此图像参数(代理程序部分的docker参数)下载节点:6-alpine Docker镜像(如果您的计算机上尚未提供)并将此图像作为单独的容器运行。这意味着: 您将在Docker中本地运行单独的Jenkins和Node容器。 Node容器成为Jenkins用于运行Pipeline项目的代理。但是,这个容器是短暂的 - 它的生命周期只是管道执行期间的。
有人可以解释我做错了什么以及为什么尝试将Node.js Docker镜像拉到Jenkins而不是本地机器?我希望在Nodejs容器中有一个单独的Jenkins容器来编排应用程序。
答案 0 :(得分:0)
我通过以root身份运行容器解决了这个问题,否则它将无法访问Docker守护程序套接字/var/run/docker.sock
...