skip to Main Content

I am trying to implement complete CICD pipe line.
I am running jenkins/jenkins:2.361.1-lts-jdk11 image on docker.
to run the docker image I use
docker run -p 8080:8080 -p 50000:50000 -d -v jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock –privileged jenkins/jenkins:2.361.1-lts-jdk11

I have connected to the repo and download the src and build without any issue.
Now I need to create a docker image though jenkins and publish in the docker hub.
Below is my Jenkinsfile


pipeline{
    agent any
    tools{
        maven 'Maven-3.8.6'
    }
    stages{
    stage('checkout'){
                steps{
                    echo 'checkout the application'
                    git 'https://github.com/hvalola/demo_jenkins'
                }
            }
        stage('build'){
            steps{
                echo 'building the application'
                sh 'mvn package'
            }
        }
        stage('test'){
            steps{
                echo 'testing the application'
            }
        }
        stage('deploy'){
            steps{
                echo 'deploying the application'
            }
        }
        stage('Build docker image'){
            steps{
                script{
                    def dockerHome = tool 'demo-docker'
                    env.PATH = "${dockerHome}/bin:${env.PATH}"
                    sh 'docker build -t pubudurana/demo_jenkins .'
                }
            }
        }
    }
}


My Docker file contains below

FROM openjdk:11
EXPOSE 8090
ADD target/demo_jenkins.jar demo_jenkins.jar
ENTRYPOINT ["java","-jar","/devops-integration.jar"]

But at the time of job running below error occurs

  • docker build -t pubudurana/demo_jenkins .
    Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.29/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=pubudurana%2Fdemo_jenkins&target=&ulimits=null: dial unix /var/run/docker.sock: connect: permission denied

please help to resolve this issue

2

Answers


  1. Chosen as BEST ANSWER

    I solved the problem by following the below post configuring jenkins

    I had to add - DOCKER_HOST=tcp://host.docker.internal:2375 in my docker-compose file


  2. you will need to run the docker build command with sudo or otherwise add your user to the docker group.

    sudo usermod -aG docker $USER
    sudo reboot
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search