[英]Running Jenkins on docker container.Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I am running jenkins inside docker container(jenkins/jenkins:lts) as a base image.我在 docker 容器(jenkins/jenkins:lts)中运行 jenkins 作为基础镜像。
I have created a pipeline in jenkins where i have added the following我在 jenkins 中创建了一个管道,我在其中添加了以下内容
node{
stage('SCM checkout')
{
git url: 'https://github.com/THIYAGU22/javaapp'
}
stage('Mvn Package')
{
def mvnHome = tool name: 'maven-3', type: 'maven'
def mvnCMD = "${mvnHome}/bin/mvn"
sh script: "${mvnCMD} clean package"
}
stage('Build Docker Image')
{
tool name: 'docker', type: 'dockerTool'
def dockerHome = tool 'docker'
env.PATH = "${dockerHome}/bin:${env.PATH}"
sh 'docker build -t imthiyagu/java-app-2.0.0 .'
}
}
After the build it can able to process SCM checkout and Mvn package but not building docker image构建后,它可以处理 SCM checkout 和 Mvn 包,但不能构建 docker 镜像
Any help?有什么帮助吗? Thanks
谢谢
The docker
command needs a Docker socket to talk to. docker
命令需要一个 Docker 套接字来与之通信。 The default socket it looks for is /var/run/docker.sock
.它寻找的默认套接字是
/var/run/docker.sock
。 You have two options of providing a Docker socket:您有两种提供 Docker 套接字的选项:
Run the Jenkins image with the --privileged -v /var/run/docker.sock:/var/run/docker.sock
arguments.使用
--privileged -v /var/run/docker.sock:/var/run/docker.sock
参数运行 Jenkins 映像。 This mounts the host's Docker socket into the Jenkins image, which can then be used by Docker.这会将主机的 Docker 套接字挂载到 Jenkins 映像中,然后 Docker 可以使用它。 Note that using
--privileged
is a security risk .请注意,使用
--privileged
存在安全风险。
Expose your host's Docker socket over HTTPS: https://docs.docker.com/engine/security/https/ .通过 HTTPS 公开主机的 Docker 套接字: https : //docs.docker.com/engine/security/https/ 。 Then set the
DOCKER_HOST
environment variable pointing to tcp://YOURHOST:PORT
, where port is 2375 or 2376.然后将
DOCKER_HOST
环境变量设置为指向tcp://YOURHOST:PORT
,其中端口为 2375 或 2376。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.