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
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.