Issue
I am running jenkins inside docker container(jenkins/jenkins:lts) as a base image.
I have created a pipeline in jenkins where i have added the following
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
Any help? Thanks
Solution
The docker
command needs a Docker socket to talk to. The default socket it looks for is /var/run/docker.sock
. You have two options of providing a Docker socket:
Run the Jenkins image with the
--privileged -v /var/run/docker.sock:/var/run/docker.sock
arguments. This mounts the host's Docker socket into the Jenkins image, which can then be used by Docker. Note that using--privileged
is a security risk.Expose your host's Docker socket over HTTPS: https://docs.docker.com/engine/security/https/. Then set the
DOCKER_HOST
environment variable pointing totcp://YOURHOST:PORT
, where port is 2375 or 2376.
Answered By - Joep Weijers
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)