Image showing How to run jenkins jobs with docker

How to run jenkins jobs with docker

🌐 This content is only available in English.
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

Not sure which of these you need? Book the free 20-minute audit — we look at one week of your work and tell you what is worth automating, what is not, and what it would cost. Book it here.

One audit call a week, Thursdays or Fridays — book early if a specific day matters to you.

Address

10 rue François 1er,
75008 Paris

When we work

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