Image showing How to run jenkins jobs with docker

How to run jenkins jobs with docker

affiliate best offer

I have successfully deployed my jenkins instance and did a good setup in my jenkins file. Now I am configuring it to run my jobs. My target is to have some task run inside a docker container.

I did the configurations but got this error : Docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

I finally managed to solve it, here is how.

My setup

I have the setup my jenkins instance. I configured a new job with below pipeline script.

node {
    stage('Build') {
      docker.image('maven:3.3.3').inside {
        sh 'mvn --version'
      }
    }
}

The issue I am having

When I run the task, I got this error:

Docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

Picture from Promise Preston https://stackoverflow.com/users/10907864/promise-preston

The solution

To solve that issue, I had to add my jekins user into the docker group to give it the permission to execute the docker commands.

sudo usermod -a -G docker jenkins

Then restart Jenkins.

Full Bright

Full Bright

A professional and sympathic business man.

Contact

Contact Us

To order one of our services, navigate to the order service page

Address

10 rue de Penthièvre,
75008 Paris

Email Us

hello at bright-softwares dot com

Open Hours

Monday - Friday
9:00AM - 05:00PM