使用Jenkins构建Node.js和React.js
我正在关注詹金斯网站的官方消息。我有一个blueocean Docker容器,它正在使用Jenkins构建Node.js和React.js,node.js,docker,jenkins,jenkins-pipeline,jenkins-blueocean,Node.js,Docker,Jenkins,Jenkins Pipeline,Jenkins Blueocean,我正在关注詹金斯网站的官方消息。我有一个blueocean Docker容器,它正在Jenkinsfile中运行管道,如教程所示: pipeline { agent { docker { image 'node:6-alpine' args '-p 3000:3000' } } stages { stage('Build') { steps {
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和节点容器。
节点容器成为Jenkins用来运行管道项目的代理。然而,这个容器的寿命很短——它的寿命只是管道执行期间的寿命
有人能解释一下我做错了什么,以及为什么试图将Node.js Docker映像拉到Jenkins内部而不是本地机器中?我想从编排应用程序的Nodejs容器中获得一个单独的Jenkins容器。我通过以root用户身份运行容器解决了这个问题,否则它将无法访问Docker守护进程套接字
/var/run/Docker.sock